In the Star Trek: Short Treks episode "Calypso", how could the USS Discovery possibly stay operational for a 1000 years? Maintenance-wise, energy-wise.
Maintenance of the Discovery is performed, one assumes, by the apparently fully sentient ship itself. Since it's basically in mothballs hanging in space, it certainly isn't beyond the realms of reality to assume that it's simply replicating the relatively small number of parts that it needs from raw materials as and when it needs them and then just transporting them into place using high-precision transport. It may also be constructing advanced radio-controlled robotic avatars when physical intervention is required.
Feedstock + Raw Materials.
The ship's tractor beams are working fine, as are scanners. Any passing raw materials (space rocks and ejecta) that look interesting can be snagged and moved into the shuttle bay for examination and to form part of the ship's supplies.
Without a crew and with other systems on low-power mode, the ship's energy reserves would be considerable. The ship itself appears to be parked in some kind of lightning storm in space. The energy from any strikes or nearby clouds may be being channelled into the ship's power network. We also know that the ship has limited warp capability which suggests that a low-level matter/anti-matter reaction is still taking place in the warp core.