I don’t think that’s how hydraulics work. You need to move oil to move the piston the other way (lowering/releasing) which means turning a pump, consuming energy.
Theoretically an excavator could be designed which uses a winch-type system to curl the bucket (maybe a highly-geared transmission from an electric motor) and then, to uncurl it, lets gravity pull it and lets the spinning winch drive a generator. I can’t think of any way to do it that isn’t extremely inefficient though.
Plus as you say, excavators don’t use a winch and motor, they use hydraulics, and I don’t think the former would be powerful enough to move lots of earth. But OP said “theoretically”, which makes them technically correct (the best kind of correct.)
There are proposed energy storage systems that involve simply lifting a lot of heavy stuff to store energy, and then lowering it again to recover it. So the idea isn’t even new. But said systems have terrible energy density (lifting and lowering stuff doesn’t store very much energy overall) and are basically a terrible idea as it is.
theoretically hydraulics can be regenerative. Whilst lowering a heavy load to the ground, the pump is being 'sucked', and the engine could be consuming no fuel during such an operation.
Practically they rarely are, because the way a piston is moved 'slowly' is to have a half-open valve with a pressure drop across it, and that half open valve wastes all the energy into heat in the fluid.