Start with the airport's web site and the hotels they list.
JFK Airport (Kennedy) - hotels, car rentals, parking, information, and more.
The Port Authority of New York and New Jersey - Newark Liberty Airport
Then try a couple of the specialised hotel booking sites such as Last Minute, eBookers, Expedia etc. The key point to look for is a free shuttle bus between terminal and hotel. Usually these run regularly in the day and on demand for middle of the night.
I once stayed at a rather grotty hotel on the JFK perimeter, being disturbed by the noise of the cleaning trucks and kitchen - but it was cheap and only about a 15 min ride back to the terminal.