Oh Theon, you utter nincompoop. The general advice is that he's lost. Various northmen armies are assembling outside the walls and Theon has 17 men to defend Winterfell with. He should probably just surrender, but that would be too easy.
So he threatens to hang Ser Rodrick's only daughter unless he calls off the attack. But Rodrick is duty-bound to attack. What a dilemma. Theon gives him until midnight but it's pretty obvious that whether he hangs the girl or not, he's getting attacked, and since everyone hates him, he's getting killed.
Maester Luwin suggests he take the black, which doesn't seem like a bad idea to Theon. Seems like a bit of an easy escape route to me.
But then, just in the nick of time, Rescue! Rodrick and all his men get attacked by some mystery force bearing the tasteful flayed man banner. I think that is the Boltons' banner. They come through the gate, and we learn that the rescuers are led by none other than...
...Reek. To be honest at this point GRRM is getting a bit predictable: the badder the character, the less likely it is that bad things will happen to them. Theon is pretty bad, therefore he survives thanks to his smelly servant.
Except he's not smelly any more and he has nice armour. That's because he's really the Bastard of Bolton, aka Ramsay Snow, now calling himself Bolton. He was supposed to have been killed for mistreating his wife many chapters back, but it turns out he swapped identities with a servant to escape being hanged. Not the most honourable man is our Ramsay, he won the battle outside Winterfell by pretending to be Rodrick's friend: shook his hand then chopped his arm off.
And here he is being all friendly to Theon, who isn't smart enough to figure it out in time... So that's the problem with being a baddie in ASoIaF: it's no guarantee that good things will happen to you because an even badder baddie might come along at any minute.