Like others have mentioned, you need to look at the two planets and the spaceship as a system together. The gravitational potential energy you gain from raising a spaceship out of one planet's gravity is equal to the energy you spend getting it out of that planet's gravity well (neglecting efficiencies).
While the trip from Planet A to Planet B might seemingly "gain" you extra potential energy because of the differences in gravity wells. The reverse trip of going from Planet B to Planet A will reverse that "extra" potential energy you gained as it's more costly to get out of Planet B's gravity well.
As so, there's no "extra" or created energy within the system. As for where energy is stored, it's simply stored as gravitational potential energy.