You can take either E subway or LIRR (faster than subway, a bit more expensive) from Penn Station to Jamaica and then Airtrain from there to all terminals. Airtrain/subway is $7.25 and Airtrain/LIRR is $10.25 off peak, $13 peak. There's also the NYAS express bus from Penn Station to all JFK terminals ($13).
You can take either E subway