Ubiquitous connectivity is envisaged for the space–air–ground-integrated network (SAGIN) of future communication to meet the needs of quality of service (QoS), green communication, and “dual carbon” targeting. However, the offloading and computation of massive latency-sensitive tasks dramatically increase the energy consumption of the network. To address these issues, we first propose a SAGIN architecture with energy-harvesting devices, where the base station (BS) is powered by both renewable energy (RE) and the conventional grid. The BS explores wireless power transfer (WPT) technology to power an unmanned aerial vehicle (UAV) for stable network operation. RE sharing between neighboring BSs is designed to fully utilize RE to reduce carbon emissions. Secondly, on the basis of task offloading decisions, the UAV trajectory, and the RE sharing ratio, we construct cost functions with joint latency-oriented, energy consumption, and carbon emission. Then, we develop a twin delayed deep deterministic policy gradient (TD3PG) algorithm based on deep reinforcement learning to minimize the cost function. Finally, simulation results demonstrate that the proposed algorithm outperforms the benchmark algorithm in terms of reducing latency, energy saving, and lower carbon emissions.