Depends on your energy requirements and future technology and energy costs. At the moment, one should value this outlay as a fixed income equivalent investment [1].
The panels have a ~25 year warranty though [2] (at which point, they should still produce ~80% of rated output), so it’s entirely possible to just leave them in place. At a certain age (~55-60), these are the last PV panels you’ll need to buy, as they’ll potentially outlive you (assuming developed country life expectancy).
[1] https://magnifina.com/articles/rooftop-solar-yield/
[2] https://www.energysage.com/solar/solar-panel-warranties/