The Persian fleet's job was to supply them with food and other necessities, as the army was too large to live off the land. It is reasonable to view Thermopylae as a delaying maneuver, although due to political differences between the Athenians and the Spartans, it's also reasonable to view the Greek defenders as having been backed into a strategic corner by indecision.
Anyway, while the Spartans and a small Athenian contingent were marching off to Thermopylae, Themistocles, an Athenian leader, sent word to Xerxes that the (much smaller) Greek navy was fearful and likely to surrender - partly true, as the Peloponnesian contingent was less firmly committed than the Athenian one. Xerxes has his navy block the Greek ships into a relatively narrow strait, but then (on Themistocles' orders) the Greeks navy ran from the Persian ships instead of giving battle. The Persians, sensing victory, chased them into the strait.
But whereas a narrow passage provided a huge geographic advantage to the Spartan and Athenian foot soldiers bunched together in a phalanx, it was a fatal mistake for a naval force, which depends on freedom of maneuver. The huge Persian navy crowded into the narrow strait, leaving the ships bunched up against each other, at which point the Greeks reversed course and attacked their flanks, laying waste to them. With his supply system in pieces, Xerxes was forced to withdraw his army.
Incidentally, the popular book/film 300, which focuses heavily on the bravery and martial ethos of the Spartans, instead depicts the Persian fleet as being destroyed by a storm prior to the decisive battle. This makes for a simpler story, but at a rather significant loss of historical accuracy.