After formatting, you can only sign in with NNIDs that are linked to that system, or make a new one. If an NNID is linked to another system, you can't sign in with it.
Yep, so you can 1) format your system (your NNID is still linked to it, but not signed in) 2) transfer the other guy's NNID onto yours (you will need the password - you have to log in before transferring), then 3) format (so signing out of the other guy's NNID) and sign back in with your NNID. If you want the other guy's games back you can sign back into his NNID whenever you like
edit: If you don't know the password, then format his console first and buy the game with no NNID.