There's a number of answers to this question, depending on who you ask. If you ask a spiritual person, then the answer is what the good posters above me have said.
If you ask a scientist, then you might get an answer like in here:
Emotion - Wikipedia, the free encyclopedia
I haven't thought about their purpose or where they come from, but my mental model of emotions is thus: emotions tell me things. If I am feeling rage or anger, then it means I've been hurt. Other emotions mean other things. I've often found that once I accept the causes of the emotions (say, I accept that I have been hurt) then the emotions tend to dissolve and I feel better. Happiness, likewise, tells me things are going well or I am satisfied (depending on the kind of happiness I'm feeling).
Another view I've been experimenting with is the idea of emotions (especially negative ones) being examples of cognitive dissonance, which is uncomfortable tension caused by holding two conflicting concepts. Such as thinking we are whole but also recognizing that we have been hurt. I'm still working out the details here.
