These are two very safe neighborhoods. To get to Grand Central Terminal from Gramercy park all you need to do is to go to Park Avenue South and catch the uptown #6train. You can get on the #6 at either Fourteenth Street or 23rd Street. I think that 23rd street might be your best bet as 14th is by the park and could get a little creepy late at night.
the last departing New Haven trains are 1:49 AM (to new haven, express to Stamford), and 1:53 AM to Stamford. after that the terminal is closed until about 5AM. you miss that and you might as well bunk at your friends place.