I was going to say the same thing. Take him to the vet and check out the urinary tract infection. THEN rip out the carpet, hard floors as so much better.
After you rip out the carpets and before you put the new flooring in; make sure seal the floors; so no odor will stay.