In recent years, solar power technology and energy storage technology have advanced, leading to the increased use of solar power devices and energy storage systems in residential areas. Carbon management has become an important method to help the community manager guide energy consumption in a timely manner, effectively reduce the carbon emissions of the community, and reduce the substantial harm to the environment. This paper aims to study the issue of carbon management and resource allocation in an intelligent community with combined heat and power (CHP) systems and solar power. The presence of heterogeneous load demands in the power grid was considered. The main objective was to minimize the average system cost over time, which included the costs associated with the power grid and gas. The Lyapunov optimization theory was employed to solve the non-convex optimization problem of carbon management and resource allocation without energy sharing. To solve the energy-sharing problem, we designed an energy-sharing algorithm based on the Q-learning algorithm. Lastly, we conducted extensive simulations using actual trace data to validate the effectiveness of our proposed algorithms.