Possibility #1: Anakin survived because, by the time Order 66 was issued, he wasn't a Jedi any more. He wasn't even Anakin any more. He was a Sith Lord named Darth Vader. Since Order 66 was "Kill all Jedi", and Vader wasn't a Jedi, the Order simply didn't apply to him.1
Here's how the Anakin/Vader change and the issuing of Order 66 plays out in the script - note that Anakin becomes the Sith Lord Vader just before the order is issued2:
ANAKIN kneels before PALPATINE.
ANAKIN: I pledge myself to your teachings. To the ways of the Sith.
PALPATINE: Good. Good. The Force is strong with you. A powerful Sith you will become. Henceforth, you shall be known as Darth . . . Vader.
ANAKIN: Thank you. my Master.
PALPATINE: Rise, Darth Vader.
Palpatine moves over to his desk.
129 EXT. KASHYYYK-MEETING HALL-DAY
YODA winces, closes his eyes, and holds his head. He feels a disturbance in the Force.
130 INT. CORUSCANT-CHANCELLOR'S OFFICE-EVENING
PALPATINE is putting on his dark cloak: he is now fully DARTH SIDIOUS.
PALPATINE: Because the Council did not trust you, my young apprentice, I believe you are the only Jedi with no knowledge of this plot. When the Jedi learn what has transpired here, they will kill us, along with all the Senators.
ANAKIN: I agree. The Jedi's next move will be against the Senate.
PALPATINE: Every single Jedi, including your friend Obi-Wan Kenobi, is now an enemy of the Republic. You understand that, don't you?
ANAKIN: I understand, Master.
PALPATINE: We must move quickly. The Jedi are relentless; if they are not all destroyed, it will be civil war without end. First, I want you to go to the Jedi Temple. We will catch them off balance. Do what must be done, Lord Vader. Do not hesitate. Show no mercy. Only then will you be strong enough with the dark side to save Padme.
ANAKIN: What about the other Jedi spread across the galaxy?
PALPATINE: Their betrayal will be dealt with. After you have killed all the Jedi in the Temple, go to the Mustafar system. Wipe out Viceroy Gunray and the other Separatist leaders. Once more, the Sith will rule the galaxy, and we shall have peace.
131 INT. CORUSCANT-JEDI TEMPLE ENTRY-NIGHT
ANAKIN goes to the Jedi Temple with a battalion of Clone Troopers.
132 EXT. UTAPAU-TENTH LEVEL-LANDIXG PLATFORM-DAY
The battle between the CLONES and the DROIDS rages throughout the sinkhole. OBI-WAN rides up to CLONE COMMANDER CODY.
OBI-WAN: Commander, contact your troops. Tell them to move to the higher levels.
CLONE COMMANDER CODY: Very good, sir.
CLONE COMMANDER CODY starts to move away, then remembers something and returns to OBI-WAN.
CLONE COMMANDER CODY: (continuing) Oh, by the way, I think you'll be needing this.
He hands OBI-WAN his lightsaber, and the LIZARD rears up.
OBI-WAN: Thank you, Cody, (smiling) Now let's get a move on. We've got a battle to win here.
CLONE COMMANDER CODY: Yes, sir!
OBI-WAN and the LIZARD ride off down the wall of the giant sinkhole.
The battle rages throughout the city. CLONE COMMANDER CODY (2224,) takes out his comlink and listens to the HOLOGRAM OF DARTH SIDIOUS as, far below, OBI-WAN can been seen battling DROIDS on a landing platform.
DARTH SIDIOUS: Commander Cody, the time has come. Execute Order Sixty-Six.
CLONE COMMANDER CODY: It will be done, My Lord.
The HOLOGRAM disappears, and CLONE COMMANDER CODY gestures to a nearby Clone Trooper.
CLONE COMMANDER CODY: Blast him!
Possibility #2: Anakin survived because Order 66 only applied to Jedi who were accused of acting against the Republic:
According to this answer, the text of Order 66 was as follows:
Order 66: In the event of Jedi officers acting against the interests of the Republic, and after receiving specific orders verified as coming directly from the Supreme Commander (Chancellor), GAR commanders will remove those officers by lethal force, and command of the GAR will revert to the Supreme Commander (Chancellor) until a new command structure is established.
If Anakin wasn't accused of "acting against the interests of the Republic", he wouldn't be targeted. His actions at the Temple would certainly suggest that he was serving Palpatine (the head of the Republic Senate) and opposing the Jedi, so the clones may have accepted him as "loyal", whereas the other Jedi were seen as "traitors".
Note about the previous answer:
I think DVK's answer is good, but Star Wars Databank disproves it. The problem is with the claim that the troopers who accompanied Vader to the Temple hadn't received Order 66. Here are the facts:
Those troops were part of the 501st Legion, and were led by Commander Appo, who answered directly to Anakin Skywalker.
The 501st were ordered to accompany Anakin to the Temple and kill all the Jedi there.
When Anakin left after killing the younglings, and went to Mustafar, the 501st remained at the Temple.
They were guarding the Temple when Bail Organa arrived. Just after Organa's arrival, a Padawan appeared, and killed several clones and wounded Commander Appo, before the other clones managed to kill the Padawan.
The official Star Wars site's Databank has a video of the Padawan's emergence and death. It is called "Bail Witnesses Order 66".
The Padawan is named Zett Jukaska, and Star Wars Databank's entry on him confirms that his death was part of Order 66.
ZETT JUKASSA A young Padawan, Zett Jukassa fought heroically after clone troopers marched on the Jedi Temple to carry out Order 66. He fell in battle as a horrified Bail Organa looked on.
Anakin Skywalker discovered the terrible truth: The Sith Lord was Palpatine himself, the puppeteer behind both sides of a war engineered to weaken the Jedi and transform the Republic into a massive industrial and military war machine under his control. But in discovering Palpatine’s secret, Anakin also fell prey to his lures. He became the Sith apprentice Darth Vader and marched on the Jedi Temple as part of Order 66. The massacre in the Temple left the Jedi Order all but extinct, reduced to a handful of fugitives and hermits.
- The only logical way to explain the fact that they received Order 66, but didn't kill Anakin, is to say that Order 66 didn't apply to Anakin, and the clones knew this. The most likely explanation of how they knew is, as my answer says, that they were told by Palpatine, or figured it out when Anakin started killing Jedi, or figured it out when Anakin accepted the order to kill Jedi.
However, we just don't know how the troops learned that Anakin was exempt - the more you dig into this question, the more confusing the information becomes.
1The mechanics by which the Clones distinguished Jedi from non-Jedi aren't made clear, but it doesn't matter much. Palpatine might have told the Clones Vader led to the temple that Vader wasn't a Jedi, and shouldn't be killed. Since the other Clones were scattered throughout the galaxy, Palpatine could inform the rest of the army about it at his leisure. This is assuming that the Clones couldn't distinguish a Jedi from a non-Jedi on their own. After all, if someone is hacking baby Jedi to pieces and taking orders from a guy who orders all the Jedi to be killed, that person is probably NOT a Jedi.
Really, the only clones who needed to know that Vader was no longer a Jedi ASAP were the ones he took to the temple before slaughtering the Younglings. These troops could have identified Vader as a non-Jedi by the fact that he was killing Jedi Younglings. If someone slaughters Younglings, he isn't a Jedi. Or they could identify him as a non-Jedi if Palpatine said "You men go to the Jedi Temple with Darth Vader and kill the Younglings". If someone is called "Darth", he's not a Jedi.
2All emphasis mine.