I wonder if you could build a stirling engine utilizing the temp different between the side of spaceship facing the sun and the side in the shadows.
Yes you can, but the reason why stirling engines are not used in space is because space assets(satelites mainly) are typically designed to operate for years(if not decades) without service/maintenance. It would be very difficult to do that with moving parts in a stirling engine/generator setup - lubrication, bearings, piston seals, friction surfaces, etc, all extra points of failure.