You can ask for a 72-hour shore pass application from your airline counter when you check in before your flight to Narita. A person at your airline counter will look at your tickets and write an application for you to take to the immigration officer in Narita. It basically has your name and flight details on it, signed by an airline official (the counter person).
Head to immigration after landing in Tokyo and get in line. When you get to the immigration window, you give the officer the application. He'll ask why you want to leave the airport and all you have to say is that you want to look around the temple in Narita during your 6-hour layover. He will put a 72-hour Shore Pass in your passport.
You should leave plenty of time to go through immigration and to get back through security. Sometimes both can be backed up and it can take forever. Other times, though, can be empty and you walk right through.
Some airlines have been known not to issue a Shore Pass application (they probably don't know about it.) I don't know if they still do it, but once I was able to get the shore pass issued at immigration. I would check one of the info places at immigration before the official windows if you want to try this.