Do dogs wag their tails because they are happy? Yes and no.....
A dog's tail is a part of a dog's body language and allows them to communicate. Dogs wag their tails when they are happy but also when they are feeling "alert" or "agitated".
A dog's tail is part of a complex system of body language that the domestic canine uses (along with "verbal" cues such as barking, growling or whining) to communicate. A wagging tail indicates excitement or agitation - but whether he means it as an invitation to play, or to warn another dog or person to stay back, depends on other body language.
A wagging tail that curves down and backs up into a "U" usually indicates a relaxed, playful dog. If his ears are erect and pointing forward, and he is in the classic "play bow" position, he's inviting you to play.
A tail that is held higher, whether wagging or not, indicates dominance and/or increased interest in something. If the end of the tail is arched over the back, and is twitching back and forth, you may be faced with an aggressive dog.
The tail is a purely social indicator for other living things. A dog doesn't usually wag his tail when alone. For instance, say you pour your dog a bowl of food. He may wag his tail excitedly at the prospect of eating. But if he comes upon the bowl already filled - without anyone being around - he most likely will not wag his tail. He may still be happy to eat, but there's no one around to whom he can communicate his state of mind.