There are buses that go from JFK and LaGuardia to Penn Station (34th St. and 8th Avenue) and Grand Central (42nd St. and Park Avenue). They cost about $10, so if you’re traveling alone and have lots of time, it’s worth it. If you’re not traveling alone, you might as well take a cab because the cost might be a little bit more, but it’ll take a lot less time. The buses run every half hour or so (and you don’t have to buy and advance ticket, just look for a sign on the sidewalk near the cabs station) but you have to wait for that and then the bus stops at every terminal. Bottom line, you’re looking at a two-hour trip to get from the airport to Manhattan. A cab from LaGuardia into Manhattan will take about 20 minutes in no traffic. JFK is probably 10-15 minutes further.
There’s also a way to take the subway from JFK to Manhattan (no trains from LaGuardia) and it costs about $8 and will take atleast an hour to get to your destination, but probably more like an hour and a half.