Is happiness or pleasure an evolutionary programming for survival?
Our current understanding is that pleasure is one of the major ways your brain gets "you" to do things, it is the basis of positive reinforcement of behavior and associative learning. It can almost be thought of a a tag for an individual behavior that says "do this again/more". That pleasure alone can motivate animals to do things has been understood since way back in the Skinner box experiments where a wire to the pleasure center was inserted in rats and said rats would keep doing whatever behavior they associated with stimulation via the wire foten to the exclusion of all else. The basis of our learning could be summed up as do things that elicit pleasure, don't do things that elicit pain. tying many complex behavior to a single signal seems to make it easier to control and even prioritize very complex behavior, just do whatever yields the most pleasure, of course humans and many other animals have many more competing emotions and other factors, like metacognition. But for simpler animals it is easy to see how this system is efficient, it is easy to tag new behaviors or experiences into this system, at its simplest form just connect (possibly inhibitory)a few neurons triggered by the behavior or memory of the behavior to the pleasure center. 

Of course it is not perfect, few things that evolved are, behaviors that are not beneficial can trigger the system, especially novel or extremely rare behavioral options, especially ones created by technological advancement, drug addiction being a great example. Evolution is very poor at preparing organisms for novel conditions like the modern technological world. And the our brain did not evolve under conditions where cocaine (as an example) existed. Just because something is pleasurable does not mean it is beneficial.  The full range of behaviors that can elicit pleasure would be well beyond the scope of a single question but it is quite clear pleasure itself is an evolutionary advantage, it is one of the major reasons we learn to eat, drink, reproduce, and make social connections. 

Happiness, is more difficult, mostly because it is a poorly defined term in biology, it is unclear if it is distinct from simple pleasure.