You can only claim the credit in the year the solar installation was completed and paid for. That would be 2024.
Note - The roof replacement is not part of the solar installation. You add the cost of the roof replacement to the basis of the home when it is sold.