Turn off the water heater at its controls. Close the gas valve to the water heater (WH) or shut off power to it. Open the hot water faucet at the kitchen sink and tub or shower in order to purge all the hot water in the tank, let it run until it is cold, and then shut of all the faucets you opened. Go to the WH and shut off the water supply valve to the water heater.
Drain the WH by attaching a hose to the drain valve at the bottom of the WH and running it outside or to a floor drain or a drain that is below the level of the WH, then open the WH drain valve so that water can drain out of the WH through the hose. You will need to break the vacuum by opening the T&P valve (if it is funtional) or the faucets in the house which will allow water to drain out. It will take some time for all the water to drain out.
Once it is empty you can replace the T&P valve (this would be a good time to replace the anode rod). Then, reverse the whole process.
Close the drain valve, remove the hose, and open the supply valve so water will start to fill the WH. Leave the faucet open so all the air in the line will be pushed out (there will be air in lines at all faucets but you can bleed them out later). Once water is flowing and air is expelled, inspect the T&P valve for leaks. You can then turn the power on (for electric WH) or gas back on and relight the pilot (for gas WH).