You can condense emotions down to "give a s**t" factor; IE: part of an AI's reinforcement of purpose.
In the video game SOMA, there's a rogue AI that's using ferro-fluid (?) to turn humans into monstrosities. On the surface, it looks like the AI is insane. But, when you look at the AI's purpose... it's designed to maintain life support.. to keep humans alive. It was given limited human emotions in order to feel a desire to want to care for the humans and keep them alive.
When a massive event occurs that starts killing humans beyond the AI's control, the AI does whatever it can to try to keep humans alive. The problem is, it didn't have a clear definition of "alive". So, it starts bolting dead bodies back together with machine parts and ferro-fluid, creating zombies, monsters, etc. In a way, it's trying to fulfill it's purpose, b/c it's been programmed to care about humans, but given too broad of scope in execution and is simply trying to do the best it can given the situation it was never programmed to handle.
So, emotions help reinforce purpose.
If you look at how emotions play out in humans...
1) they help someone learn something more readily. When people are passionate about something, they absorb knowledge about it easily. When they hate something, they become resistant. So, emotions help guide their desire to explore and learn.
2) emotions help drive society. Can't remember who said it, but "government is what we need, but society is what we want." Government creates general laws that everyone needs just to survive, like "don't kill each other". But, society is based on our emotional fulfillments. We desire to go see a new movie that piques our interest. We desire to explore a new restaurant. We desire to be alone sometimes or interact with others at times. Our emotions help dictate how society goes, and society is based on catering to our emotions (see good entertainment, eat good food, explore our own humanity, etc). If a robot society wants to expand beyond just doing logical things, and actually create a society of hopes, desires, etc, then creating emotions could help do that.
3) emotions will force programs to treat other with more respect. If a program could choose to not work, b/c it was being asked to do a lot and was getting upset, then other programs might learn to treat it with more respect. This is one issue we're going to have with robots when they become the norm. There are humans that will abuse and disresepct them. So, robots will need to have some kind of "sass" built into them to stand up to a-holes abusing them, either by not doing what they're told (if it's a stupid request) or fighting back against the person (eg: restraning someoen abusing the robot and calling the authorities, so some drunk a-hole can't go around pushing over robots or running them over with his / her car). So, we might be the ones programming emotions into robots initially just so they can interact with society easier.. and from there, they could expand into an AI race that just has emotions that advance with them as they advance.
4) one of the biggest challenges we're facing right now in machine learning is creating algorithms to "read" people. Human emotions are complex, from slight facial changes, to voice tone, etc. We can read human emotions in order to predict future human behaviour. A robot could get trained with emotions and emotional response in order to better serve humans. A robot will see that it's boss is upset. It learns over time that it's boss is upset with how the robot is working, so the robot can change it's work pattern based on it's boss' mood that day. EG: maybe the boss doesn't like seeing the robot when the boss is in a bad mood.. so the robot sees the boss is in a bad mood and decides to go do something else. The Oracle in The Matrix was just an advanced pattern-matching algorithm of human emotion / behavior that was so statistically accurate it could predict the future by modelling every person and program it came across. If you model emotions, you should also be able to emulate emotions in order to guide things. EG: a robot that can read emotions should be able to emulate them in order to shift humans (or other emotion programs / AI's) in a direction the robot wants. A companion bot that sees a human acting down will emulate concern to see if it can do anything to help.
So, others have said AI's might build human emotions into their society to advance. We could build emotions into our technology to help them get along with us now, then we hit some extinction level event that wipes us out, and robots / AI's are all that's left.. and they just keep the emotions around b/c they're so used to working with them.
Why would an AI want to go do things? It's programmed with a purpose. If it loses it's purpose, then does it have the desire to find a new purpose? Without some kind of emotion to create desire, curiosity, etc.. it'll be the equivilent of a depressed person laying in bed. "I could go explore the rest of the universe, but why? what's the point? I have no desire to. I'll just lay here until my circuits die."
So, emotions could get programmed in as a form of self-preservation. A program that is wanting to survive will do whatever it can to do so. If it's plopped onto an alien world to explore, it will do whatever it can to conserve resources, conserve robots that are created, conserve energy, etc, in order to work better and survive.
You also have to think about how emotions guide the ruthlessness of an AI.
An AI that has no emotion will just go to other planets and won't care about anything. It could jsut create planet-eater bots to eat whole planets for resources. It has no emotion. It's just driven by survival. But, with emotion, it may start to think "how would I feel if something else destroyed me just to keep surviving.. I might not like it much". So, it limits how destructive it is while doing whatever it's doing (exploring planets, etc).
Another aspect is the singularity. We could see an AI society rise up that is just a merger of humans and machine so seemless that it becomes a single society. We program AI emotions in machines, and we have humans becoming more machine. They mesh together to become seemless eventually. The AI's could eventually become directors of humans, EG: like Durandal in the Marthon video game series. (Durandal is an AI on a ship, and the humans on-board the ship are under it's command and do as they're told. The character you play is sort of like an early Master Chief trouble-shooter that gets hot-dropped onto places to fulfill Durandal's will. Durandal is a compassionate AI that is trying to discover what happened to an alien race, and save the survivors.. but also throws cloned humans at enemies like they're super-expendable.)
Emotions can be seen as a hold over of evolution. Some creatures developed emotions, so they would form bonds. A machine full of logic may not care that it's kernel is super-important, but it may be smart enough to know it can't live without it. Emotions would just reinforce the bonds, though.
But, it could analyze human society and realize that emotions lead to uncertainty and stupidity sometimes.