Could Tywin have asked Robert to release Jaime from the Kingsguard immediately after the rebellion? And send him back to Casterly Rock. Also if the answer is yes, I don’t understand why he didn’t do it.

He could have asked, but Robert wouldn’t have necessarily said yes…

However, the way Tywin phrases it here suggests that he did see Jaime’s vow as binding until recently:

Lord Tywin glanced at Jaime’s stump again. “You cannot serve in the Kingsguard without a sword hand—”
“I can,” he interrupted. “And I will. There’s precedent. I’ll look in the White Book and find it, if you like. Crippled or whole, a knight of the Kingsguard serves for life.”
“Cersei ended that when she replaced Ser Barristan on grounds of age. A suitable gift to the Faith will persuade the High Septon to release you from your vows. Your sister was foolish to dismiss Selmy, admittedly, but now that she has opened the gates—”
(Jaime VII, ASOS)

So it may well have been that he thought at the time that it was unthinkable that a member of the Kingsguard would be dismissed from office, but once it happened, he was happy enough to use the precedent (and a fair bit of bribery) to get what he wanted. 

What real-world precedents are their for the KingsGuard? Are they usually a state’s ‘best’ soldiers? I’ve always wondered that having to stand around on guard duty all day (especially for when the royal family waxes large) would make them less effective than a conventional, regularly working sellsword. How did they maintain their fearsome reputation?

The Kingsguard are something of a pastiche between your Royal Guards (think the guys in the giant bearskin hats) and various historical orders of knighthood: the Knights of the Garter or the Knights of the Golden Fleece.

They tended not to be the best soldiers per se, but the most disciplined, because you wanted them to be on their guard to defend the person of the monarch. Hence why Royal Guards “may not eat, sleep, smoke, stand easy, sit or lie down during your tour of duty.“

RE: Jaime. Shouldn’t we just asume that Kingsguard vows take precedence over the knighthood ones, if they ever come into conflict?

Well, you know what they say about assuming things…

But seriously, unless otherwise stated, it would be much more likely that the earlier binds the former, just as legal precedent itself means that older decisions are binding on future decisions. In this case, my contention is that, having sworn the oath of knighthood, Jaime is not in fact completely free to swear to “Defend the king. Obey the king. Keep his secrets. Do his bidding. Your life for his” in any situation where obeying the king or doing his bidding would cause him to violate the first oath.

To take an example that’s not too farfetched given events in ASOIAF: given that the oath of knighthood requires knights to “protect all women” and to “defend the young and innocent” should a kingsguard obey Joffrey’s command to beat Sansa? I would argue that Sansa’s ACOK chapters suggest strongly that any knight who obeys such a command is not a true knight, whether we’re talking about brutes like Boros Blount or Meryn Trant or the squeamish like Arys Oakheart.