These words are mostly used for greeting our friends and family on their birthdays. Sometimes they are used for wedding anniversaries, and even as a response to Merry Christmas and Happy New Year wishes.
The greeting is intended to convey happy birthday wishes, but also the hope that this happy day will return many more times. The phrase is a bit formal, and is in more common use in British English, Indian English and Canadian English, than it is in American English. It is, actually, a part of a truncated phase that should read something like I hope you have many happy returns of the day.
The first recorded use of the phrase was in a letter from 1789 by Lady Newdigate (Hester Margaretta) to Sir Roger Newdigate, her husband, and it is used as a wish for their wedding. Even earlier, Joseph Addison uses the phrase in his political discourse The Freehold (1752), where he says that ancient Romans used the phrase Multos et Foelices (many prosperous and happy) as a means to convey happy birthday and many happy returns of it.
There are many variations of this greeting, such as Many more happy returns of the day. By greeting our friends and family with any of these words, we wish them happiness and long life.