Hi Dune,
There are probably several ways to approach breaking down your scene for rendering with Terragen's Render Layer feature.
You can use the Clipping distance parameters under the Layer Settings Tab to isolate the background (glacier, sky) and foreground (cave people), perhaps even the midground if necessary.
You can group your cave people together by selecting their nodes and pressing "CTRL G", and then assign that group to one of the Object Groups under the Render Layer's Objects tab. This will allow you to render them separately if you wish, and you could do the same for the foreground vegetation too.
For shadow passes, you could add the Shadow Catcher Shader node at the end of the Shaders group and select "Shadow ratio", leaving the rest of the settings at default. You would need to do this to the shader network for any 3D object you want to be included in that render. You also need to disable GI, Atmosphere, and the cloud layer's Enable Primary setting, and possibly set the Background object's colour value to white; basically anything that could contaminte the shadow pass which you want to be black and white. Note that this would be a separate scene. I'm working on adding some practical examples of this to add to the wiki page:
https://planetside.co.uk/wiki/index.php?title=Shadow_Catcher_ShaderFinally, here's a link to compositing the render elements created via Terragen's Render Layer feature:
https://planetside.co.uk/wiki/index.php?title=Compositing_Terragen_Render_ElementsAnd, Parts 25 and 26 of the Terragen for VFX video series deals exclusively with Render Layers and specialized masking techniques for use in compositing.
https://planetside.co.uk/terragen-tutorials-for-vfx-section5-rendering/