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.
We can speculate on how this would be possible based on information gathered from the show. We know that by the TNG era the ship is self cleaning, as described by Riker in "Up The Long Ladder". So by that point the ship seems to have an advanced (we never see it) system for self maintenance.
Having said that, in the absence of a crew the amount of mess and wear would be greatly reduced.
On the Discovery show the ship's computer has been shown to "synthesise" things. This seems to be a precursor to replicators. It was never made clear how the TOS era food delivery system worked, if it was some kind of giant store or limited kind of replicator. What seems certain is that the ships of that era have some ability to produce new parts and material when needed.
Considering the vast amounts of energy needed to travel at warp speed, if the ship remained stationary with minimal life support it should have plenty of power to remain operational for a millennia.