I have been told (but not tried it myself) that if you sell a module in outfitting, then swap ships (at the same station) you can buy back the module for your new ship.
You can only do this at outfitters which can outfit the specific modules. For example, if the station does not sell FSD's, ie it says not available at this station, you can not buy back a FSD that you have sold there. I was advised to find a station which you can buy every type of module from and make that your base for new and old ship.
If anyone has tried the above, can they confirm that this is correct as I haven't got round to upgrading like this yet and my ship is currently out in the black exploring toward the Pleiades
