I know it is difficult, but not reacting is the best thing you can do. Yelping is okay, but don't pull or shake him off balance. Just take your hand away quickly and quietly leave him. The best thing to do otherwise is to familiarize yourself with the warning signs of biting or aggression, as well as the times and situations when your bird is most liable to bite. In your case, when going back in the cage. Try to make these moments as quick and stress-free as possible. Don't loiter around near the cage before putting him back if it stresses him out to do so. Just take him in the room, put him back quickly and leave.
Back on the topic of biting, never punish your bird for biting as you would a dog or child. They don't necessarily understand nor respond to this. Also, they're many times smaller and physical punishment won't be helpful, and at best, harmful. I do "punish" my bird in a sense. If they get nippy or crabby, I put them back in their cages or won't let them sit on my hand or shoulder and be petted. This way, they see affection as a privilege, and they get that they won't get anything good out of biting or being nippy when playing.
In your case, I recommend just using this "punishment"-- putting him away when biting and disallowing affection to reduce the biting behavior. Also, try your best to limit your reaction to the bite itself.