The price you can sell energy at is guaranteed (government subsidies). Your investment (maybe 100,000 €) will pay itself off in about twenty years (including insurance and the occasional maintenance). Modern solar panels have a lifetime of more than twenty years.
Because of all this banks will be more than happy to give you credit and if you have the necessary space you would be stupid if you didn’t do it. It’s free money.