Some of the energy efficiency credits only apply to your primary residence, but the solar electric credit applies to any property you own, Remember that if you put the solar property into service on a rental, you take depreciation based on the cost after the tax credit, not the gross cost.
The home needs to be your residence. It can not be used for a rental property. The credit for solar panels is in Section 25D of the Tax Code:
However, a taxpayer may claim a § 25D credit for other qualifying properties described in § 25D that are not fuel cell properties (solar electric property, solar water heating property, sm
all wind energy property, and geothermal heat pump property) installed in or on a dwelling unit used as a second home or a vacation home by the taxpayer. But a taxpayer may not claim the § 25D credit for expenditures for improvements made to an investment property, such as rental property, that is not also used as a residence by the taxpayer.
https://www.irs.gov/pub/irs-drop/n-13-70.pdf
The term “qualified solar electric property expenditure” means an
expenditure for property which uses solar energy to generate electricity
for use in a dwelling unit located in the United States
and used as a
residence by the taxpayer
.
https://www.law.cornell.edu/uscode/text/26/25D#d