Obviously you have already done some reasearch. You should count 3 hours (both rides together) to the train rides, just to be safe, and plus leave 2 hour margin before the flight. You did not specify at what time you arrive? But If you had, lets say 6 hours of time to spend in Tokyo, I would definitely go! My favourite city on the planet!
If you were to arrive to Ueno, you could probably see Ueno+Akibahara. If you were to arrive to Tokyo Station, you could check the Park around the ruins of Edo-jo. Asakusa is nice too, with the Sensoo-ji. Though basically you could go anywhere quite easily because of Yamanote line is so convenient. Anyway, I too have heard that Narita City is nice, but I've never been there myself. It's right next to the airport.
Ps: Oh, there is faster train also; the Narita Express, but it's quite expensive and to be safe you should book the tickets in advance. I almost missed my flight to Helsinki once, because I did not realise that NEX could be sold out.