As such, using a different passport to board the plane than the one you plan to use to enter the destination country is not a problem and probably pretty common. If there is an exit passport check in the country you are leaving, you can also show a different passport at check-in and to the border guards or, if you are unsure, simply show both passports and explain your situation.
However, one issue in this case is that the details of the passport you provide to the airline will be communicated to the US authorities in advance. And just about everybody apart from US citizens needs some form of advanced authorization to have the right to enter the country.
Since using your EU passport to enter the country would require either a visa or an ESTA (if eligible), I assume the US authorities might automatically check if you do have one of those (which you are not supposed to, I think) based on the info communicated by the airline. If that's true, then you would need to apply for that in advance to be able to board the plane.
I also found the following in a CBP FAQ about ESTA:
If you are a citizen of the U.S., and also of a VWP country, you should not be applying for ESTA. One of the requirements of being a naturalized U.S. citizen is that you apply for, and use, a U.S. passport for your travels. While we are aware that in some cases, naturalized U.S. citizens use their alternate country's passport to travel, our expectation is that you will use the U.S. passport to travel from another country to the U.S. at both points of travel, departing the foreign country, and arriving into the U.S.
If you have a true emergency, and are unable to obtain a U.S. Passport before your travels and have only a VWP-eligible country's passport, then you will have to file with ESTA to use that passport to travel to the U.S., and you will have to use the non-resident queue when arriving at the U.S. airport using the foreign passport. Note: It is important to PRINT a copy of the document for your records. The printout is not required upon arrival into the United States, as the officers have the information electronically. Some airlines require the printout upon check-in, please check with your respective airline.
It's obviously not intended as a full explanation of the law and kind of dances around the issue of what's really allowed or not and what the consequences might be but it does imply that they don't want you to apply for an ESTA and travel on your non-US passport. At the same time, the text also suggests that it's a possibility and that people do get away with it. (Confusingly, it only discusses “naturalized U.S. citizens” but I thought this requirement applied to all US citizens).
The simpler approach is to board the plane in the EU with your US passport, use it to clear customs/immigration in NYC and only switch to your EU passport when entering the next country. Panama (or other Central American countries) won't know or care about the passport you used to board the plane. EU countries don't care either but you can always show border guards your EU passport and use the “EU citizens” queue even if you used your US passport to check in.
For the return flight, you can use the same approach. Since US citizens enjoy visa-free access to all EU countries, you probably won't be asked anything if you only use your US passport. But if needed, you can still show both passports to the airline and yet have them register your US passport's details for APIS purposes, thus obviating the need for an ESTA or a visa. (Do show the EU passport to border guards in the Central American country you are leaving, so that they see the relevant visas or entry stamps, as applicable.)
You could even have a visa for your final destination (if needed) in another passport than the one registered in the APIS system for the benefit of US authorities. If you need a visa, the ground handling personnel at your airport of departure will probably want to see it as well – to ensure you have the right to enter your final destination – but this is not a problem: You can always show them both passports and ask them to enter the details of the US passport in their system.