They open the pocket that the pacemaker's put in, disconnect the heart wire(s) from the old pacemaker and connect a new pacemaker in its place. The old pacemaker gets sent to the maker if its battery failure was premature or if you ask they make give it to you as a souvenir!
The new pacemaker will probably have more "functionality" than the old with the ability to read its battery level, and the amount of charge it has to use etc.
They normally don't have to replace the wires, so it's a simple process.