First of all, I haven't read the book (shame on me).
I remember one of the last scenes of Lord of the Rings: The Return of the King shows Frodo, Gandalf, Bilbo and some others leave by ship.
Where are they going to, and why?
Frodo leaves Middle-earth for the Undying Lands with Gandalf, Bilbo, Elrond, Celeborn, and Galadriel.
This is considered a mystical land, home to the Valar, 'angelic' beings, also known as the 'masters of spirits'.
From the LotR wiki:
In TA 3021 (Third Age), Círdan the Shipwright accompanied Elrond, Galadriel, and Gandalf, the Keepers of the Rings, on a voyage to the Undying Lands, where they intended to remain. They were also joined by Frodo and Bilbo Baggins, Hobbits who were among the very few mortal beings to be allowed passage to the Undying Lands. Eventually, Samwise Gamgee, another Hobbit of the Shire, and the Dwarf Gimli along with his good friend Legolas, are also said to have made the journey.
Now, as to why they made the journey, there seems to only be speculation, although the most common agreement is that Tolkien chose to have his beloved characters travel there, seemingly to remain, in order for them to live forever.
EDIT: It has been pointed out that, as mortals, eternal life would not be an option for the hobbits, so perhaps we should consider it more of a happy retirement.
Another, more thorough, answer could be the following, from Yahoo:
His [Frodo's] journey to Mordor had scarred him, physically and emotionally. He would never fully heal. Arwen gave him her seat on the last ship (the only thing of note she ever did in the whole danged book) so that he could find rest. All of the ring bearers left Middle-earth; Gandalf, Galadriel, Elrond, Bilbo, Frodo, and even Sam after his children were grown and Rosie passed away.
The characters you mention are accompanying the elves - Galadriel, et al. - back to Valinor, the Undying Lands, across the sea to the west. The reasons for the elves' departure are detailed in The Silmarillion. It's a long story, which I encourage you to read, but to summarize very briefly:
Gandalf goes with them because that's where he's from. He's one of the Maiar, essentially a minor god. He's only in Middle Earth because he was sent there on a mission, which is now complete. He could probably magic himself back but it's not his style, so he travels with the elves.
As for Frodo, Bilbo, and eventually Sam, I don't think the reasons are explicitly stated. It seems that they have been invited to live among the gods - an unprecedented honor for anyone not an elf - as a reward for their service related to the Ring.
They are traveling to Valinor, the Undying Lands, which exist outside the human world. Men cannot go there. The ending of LOTR ties back to material from the Silmarillion. The Appendices to The Return of the King provide added detail. As noted, many of the elves, Galadriel included, returned to Middle-earth in rebellion against the Vala to wage war on Morgoth, who stole the Silmarils (gems). The Vala are not "gods". There is but one creator-God in Tolkien's mythology. The Vala are created and participate with Illuvatar in fashioning the world.
Frodo, Bilbo and even Sam have been altered by their contact with the One Ring. They have also performed great deeds. Frodo is specifically given leave to travel to Valinor because of the unhealable wound from the Morgul knife. It is a grace of the Vala to permit them to come to the Undying Lands. Gimli, by the intercession of Galadriel, is also given leave to come to Valinor. Like the elves, and unlike men, the dwarves are tied to the world. Elves and dwarves go to the Halls of Mandos (a Vala) when they die. Men pass beyond the world - the "gift" of Illuvatar, but subverted by Morgoth.
The Silmarillion details the creation of the world by Illuvatar (a variant of the term "All-Father" - JRR Tolkien was a philologist and there are cognates to English, German and other languages in those spoken in Middle Earth). The Valar are created beings - created by Illuvatar in the long past. The Maiar are another angelic order of beings, below the Valar. Saruman and Radagast are of the same order as Gandalf. Sauron is also a Maia.
Why does Frodo go there?
Imagine to have experienced the most adventurous adventure any being could ever experience. What would you do afterwards?
When the Hobbits are back in the Shire they are being shown in their beloved tavern where they sang and danced so happily. After their adventure they just sit there, looking at each other, knowing that there are no other sensations left for them in this life.
Pippin and Merry might have gone beyond their physical and mental limits, but Sam and Frodo have gone beyond any limit to deliver that ring into the fire. Contrary to Frodo, Sam is a plain and simple man. He saved the world, and now he takes a woman and settles for a family. Frodo is much more sensitive in nature and cannot see anything worth striving for in his new reality. And indeed, what else is there? Why not go into another realm to feel alive again?
In my opinion, Peter Jackson crowned his LotR-work by masterly conveying the pure void the Hobbits are confronted with in the Shire.