We will be on holiday in Ibiza and before we book our return flight back to NY we're wondering whether to fly from Dublin rather than a London airport.
Will we then be able to go through Immigration there and not in the US when we land?
Yes it certainly is possible to construct an itinerary via Dublin on the way back to the US. However, none of the major alliance carriers nor their interline feeders operate a direct service on Dublin-Ibiza; therefore it will involve another stop at an intermediate point in Europe (where will depend on which airline alliance you use). Because of the way most transatlantic fares are now structured, this should not materially affect the ticket price.
Most of the NYC terminals now have the new "Automatic Passport Control" [APC] machines and I have found (as a non-US Passport holder) that entry times have been significantly reduced.
I am not sure it is worth a detour through Dublin purely to avail yourself of pre-clearance.