I don't know much about pacemakers, but I thought that a lot of them now had an inductive loop so you could charge the battery through the skin.
When I was young I saw, in a museum, a nuclear-powered pacemaker. I guess they were used before battery technology improved. The power source lasted quite a while. I'm not sure how it worked, exactly. I think nuclear batteries normally generate heat and use thermocouples to create electricity, but I don't know if that's how these worked.
Just to address a minor point, open heart surgery is not required to implant a pacemaker or defibrillator. The device itself is placed under the skin via a small incision, and the leads are passed through veins into the heart via catheters. Pacemakers implants are sometimes performed on an outpatient basis, and defibrillators typically involve just an overnight stay.