The question is not "what role does religion fulfil", but rather, "if religion wasn't there, would things have been better?". Because, e.g. many recreational drugs ALSO provide values, hope, and guidance (on one hand), and some religions like Mormonism and Scientology also provide them, but apparently forbid leaving them (read about excommunicating in either) to the point that I find unacceptable in a society.
Disregarding the obstacle of definition of religion vs. e.g. cult vs. value system, my opinion would be, based on observing mostly-religious states vs. mostly-secular states (like Sweden and Norway), would be that value provided by religion is a net negative.
 if you insist, I will say that beleief X is a religion iff there's a government of a country with >10M residents that accepts it as a religion for the purpose of its law. Specific definition is immaterial - they will all coincide for 99% of the population, and will have essentially no effect in the grand scheme of things.
Be careful. I think the general consensus about these observations is that what's happening is that less stable and secure societies tend to make people more religious, rather than that religion tends to make societies less stable and secure.
I am not aware of this consensus, but it is entirely unrelated to my claim: The supposed benefits of religion are nil, because comparable countries that essentially eschew religion fare at least as well, and usually way better than those that do not.
I did not make any claim about the relation between stability and religion. Swedes and Norwegians, as nations, are the best educated, best nourished, among the healthiest, with virtually no crime compared to e.g. the US or Italy. What exactly are the positive benefits that you get from religion that you do not get without?
Observation: Various measures of societal health are correlated with lack of religion.
Explanation #1: Religion is bad for society.
Explanation #2: Bad society is good for religion.
Both explanations are at least somewhat plausible (religion is bad for society because believing falsehoods is morally corrosive, or because religions are full of ideas founded in old moral systems that we no longer endorse, or whatever; societal ill-health is good for religion because people in difficult situations will turn to anything that seems to offer comfort, or because when things are really hard the gods really do help, or whatever). In particular, the plausibility of explanation #2 means you can't just leap from the observation to explanation #1.
For the avoidance of doubt, I am not claiming any particular benefits for religion. I'm an uncompromising atheist myself. I just don't like plausible but unsound arguments, and "The Scandinavian countries are great places and also very irreligious, therefore religion isn't good for you" is, I think, a plausible but unsound argument: it could equally be that their irreligiousness is an effect, not a cause, of their education, good health, low crime, etc.
(On the other hand, "The Scandinavian countries are great places and also very irreligious, therefore religion isn't vital for a healthy society as some religious people claim it is" is a perfectly good argument, and one I've used myself.)
[EDITED to add, on the subject of that putative consensus: see e.g. http://edge.org/3rd_culture/paul07/paul07_index.html, a single article but one written by two of the biggest names in the field, Gregory Paul and Phil Zuckerman. "To put it starkly, the level of popular religion is not a spiritual matter, it is actually the result of social, political and especially economic conditions [...] Mass rejection of the gods invariably blossoms in the context of the equally distributed prosperity and education found in almost all 1st world democracies. [...] Mass faith prospers solely in the context of the comparatively primitive social, economic and educational disparities and poverty still characteristic of the 2nd and 3rd worlds and the US." I should perhaps emphasize that GP and PZ here are talking about the origins of large-scale popular religiosity; individuals' decisions are, well, more individual and it certainly isn't true that all religious people are that way because their messed-up societies make them look for supernatural aid.]
But I want to reiterate, that I only ever claimed "sum (religion benefits) <= 0", which I believe is equivalent to your statement that "religion isn't vital" (or rather, "religion isn't helpful"). At no way did I imply any other cause and effect relation other than the one implicit in this statement.
Does it help them climb out of poverty or does it only help them reassure themself the world is exactly right, their poor lives are okay, and everyone smarter than them should be stoned to death?
It seems to me that religions that prey on unstable, unsecure societies are especially nasty these days. Evolved to conquer poor societies and keep them that way!