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?
They are traveling to Valinor, the Undying Lands. these 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 silmarillions (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 Valar) 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 Vala are created beings - created by Illuvatar in the long past. The Maia are another angelic order of beings, below the Vala. Saruman and Radagast are of the same order as Gandalf. Sauron is also a Maiar.
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.
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, a race of 'angelic' elves also known as the 'masters of spirits'.
From the LotR wiki:
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: