Its survival depends mostly on what is available to it. While photosynthesis is an option for a source of biological energy if you have the required structures, CO2, and water, sustaining that system is going to take materials you may not have access to, such as certain minerals and compounds. However, given adequate knowledge and biomass, it wouldn't be beyond reasoning to reverse-engineer the systems that create all but the mineral components here on earth. Basically, re-create a biosphere to manufacture what you need. Either with separate minion-creatures contained within the shell, or as organ-like additions to the main creature. The thing is, this isn't as difficult as it initially seems. You don't need these organisms to survive competing in the wild, you can over-specialize and make them monstrously efficient, so long as you're willing to spoon-feed and protect them. So-fungi/lichen/micro-organisms to break down rocks/dirt/excess biomass, flora to feed off of waste material from that and produce biologically usable energy & compounds, and fauna to recycle O2 back to CO2, anything more complicated than that can likely be hand-waved away for your general audience by sci-fi space-crab genetics.
Now that we've established that with preparation, sustaining your brood is possible, we need to focus on long-term growth/development. If the moon in question was formed similarly to earth's moon (in that it's mostly material cast off by the planet during its formation process and later huge meteorite impacts) than you likely won't have much problem finding and re-purposing material to feed your growing brood, so long as the process is efficient enough that it's a net-gain, not a net-loss. Again, hand wave sci-fi space crab genetics, we're looking for stuff usable in-story, not to publish a scientific article. On the other hand, if the moon was formed by snagging passing meteors (such as Mar's Phobos and Deimos) the brood is going to have a much harder time finding the components they're used to breaking down for sustenance. But there's also the chance for serendipity to smile on them as well, and find a best-case scenario even better than what they're used to. That's assuming a barren moon, unlike Jupiter's Titian or Star War's Endor.
TL;DR: we're already doing this on earth, rocks are broken down, minerals are consumed, the dead are recycled. You just need enough air, biomass, and overly-specialized organs/organisms in a concentrated space to self-perpetuate. Maybe checkout this fanfiction for some more ideas (be forewarned, the first chapter is a bit info-dumpy and tailored to those already somewhat familiar with Prototype's genetically self-modifying Blacklight)
Edit: I've been seeing a bunch of references to the square-cube law and the like, but picture a mostly-hollow creature mixed with a hive?