I would say that this is, in many ways, a "chicken vs. egg" situation. I'd say that religion was just as much a result of our evolution, as our evolution was affected by religion.
One of the most fundamental hallmarks of human evolution, in my opinion, was the development of the ability to ask "Why?". We changed from being creatures who simply experienced the world, to being creatures who sought to understand why those things happened, and through understanding, to control them and manipulate them to our own advantage. Without that crucial step, we would never have become who we are.
Thus, religion -- at least initially -- would in my opinion be mankind's first efforts at observing the world scientifically. They observed the world -- thunder, lightning, disease, earthquakes, volcanoes, etc. -- and attempted to find causes for events that happened around them. Lacking the tools or technology necessary to identify the natural causes, they were left with the almost inevitable conclusion that the causes must be supernatural.
So, they established a theory, and then set out to prove it, by forming different hypotheses, and testing them. For example, if it was a god that was causing volcanoes, it seemed most likely that this was because the god was angry at them. So they would need to establish a list of rules about what things made that god angry, and avoid them. And they would need to establish rituals and procedures to appease their god when he did get angry. And you needed people who could focus their time and energy specifically on understanding their gods, and on implementing their gods' rules.
Thus, you developed theologies, religious hierarchies, etc.
Of course, these methods didn't actually work most of the time. But occasionally they did. Sometimes just by coincidence (a volcano starts erupting, they sacrifice some children, the volcano stops), sometimes by accidentally hitting on an effective method (using certain plants that actually helped cure certain diseases). It would certainly fall far short of what we would consider the proper "scientific method" today.
But in the end, religion was -- at least at first -- a necessary and inevitable part of mankind's efforts to understand, control, and manipulate the world around us.
Of course, as religions grew, they inevitably shaped and directed the direction in which different cultures grew, also. One culture might have developed a religious system -- such as the Greeks -- where questioning one's gods and religious beliefs was quite acceptable, and where new ideas were encouraged and accepted. Another culture might have developed a religious system that was very strict and restrictive, punishing anyone who questioned or challenged it.
Religions also affected how we looked at the world. Christianity, for example, presents us with a god who encourages us to change the world around us. We don't have to accept things the way they are...we should in fact work to change them, to make them better; we should help others who are in worse conditions than ourselves; and we can pray to our god to change things for us. On the other hand, religions such as the Hindu faith teach that one must accept whatever happens, and not fight against it or try to change it, that it is gods will. You don't pray to your gods to change your situation; you only pray for the strength to endure it, and learn from it, so that in your next incarnation you can have a better life. Such things will, inevitably, have significant influence on a society's evolution and development.
And, of course, while religions formed initially as a way to try to understand and control the world around us, inevitably people who wanted power were drawn to leadership of those religions, and used those religious beliefs in order to consolidate their own power. Religions changed from being a way of examining and understanding the world around us, to being a way to control people and get them to do what you want.