Well, you have a problem with staying in the airport, first Narita is 24 hours but I recall from flying through there late at night that it's mostly shutdown after 10pm (things start to close at 8pm), so you'll find no food or drink. Sleeping In Airports agrees with me and also has this to say:
Sleeping in airports is generally frowned upon in all Japanese airports. While the terminal is open, you will likely be approached by a security officer who will ask to see your travel documents. This is from the Narita Airport web site: "Aircraft operating hours is between 6:00 a.m. and 11:00 p.m.. Customers are not permitted to remain in the passenger terminals outside aircraft operating hours. However, under special circumstances, for example when an aircraft arrives after public transport stops operating, customers may be allowed to sleep in designated areas. Moreover, customers catching early morning flights are advised to use nearby hotels and accommodations around the airport."
That link also has details of the nearby airport hotels with prices, that might seem like your best bet. You may get away with staying in the airport, but the last thing you want is to get thrown out after all the transport has stopped.
One other option is to head into Tokyo, there's lots of info on the Wikivoyage page for Narita Airport. I've checked and at least the Skyline will run late enough and early enough for you. But the question of what to do still remains, you could attempt to stay up all night (leave your bag in the airport) but I also seem to recall a lot of things in Tokyo shutdown overnight as well -- including transport. You could compare prices of local hotel vs train + hotel. Or maybe consider a capsule hotel.
If you get there early enough you could certainly just have a walk around and see some sites, maybe grab some cheap food.
One free thing you can try is Tsukiji fish market -- open at 3am, great to walk around just to have a look and with excellent food stalls/restos beside it. You'd have to be careful about travel and getting back to the airport, if you wanted you could ask a second more specific question on how to do that particular trip.
The other option is Narita itself, I've never been but it does look like it might be possible to kill a few hours there. Again, that's something you could ask as a separate question.
Make sure you have local currency if you're leaving the airport, just in case.
Also, check this page about access to Terminal 2 in the morning.