A panel repays its own making energy in a few years
Making a solar panel takes energy: mining, refining silicon, manufacturing, shipping. People love to bring this up as a gotcha. The catch is that a typical rooftop panel earns all of that energy back in roughly one to four years of sitting on a roof, then keeps producing clean power for two or three decades after. Net result is strongly positive over its life.
Source: NREL / IEA PVPS energy payback studies