Cave-ins are absolutely stopped cold by walls, ramps and upstairs (including up/down stairs) - cave-ins will destroy everything until they reach a tile supported from below. This means only the z level immediately under the surface is unsafe to dig out, if you leave it intact then z-2 will be perfectly safe. As noted, ramps and staircases are not vulnerable to being destroyed by cave-ins as they support the level above, this can be used to create traversable areas that wont get damaged by collapsing trees (it looks ugly, but you can't have everything).
If you need to dig out dirt on z-1, just pave over the surface above to prevent trees growing and bombing the vulnerable area. Floors (and any other construction or workshop - kennels are cheapest), constructed roads, fields, and stockpiles, will all work fine for this (but if you ever remove the stockpile, trees might pop into existence). Constructed walls/upstairs/ramps, not only stop trees growing, but also 'catch' a collapse and stop its propagation downwards.
To handle fungal trees, just don't dig out any area and leave it unutilized. As noted, workshops and fields keep trees in check, stockpiles do too, as long as you don't remove them. Trees appear to cause no damage when they try to grow through things which obstruct saplings from growing. For example, if a tree grows through a bridge, then while it will actually be growing through the bridge, and providing support and stuff to things above the bridge, it wont cause any damage to the bridge either in growth or being cut down. Trees growing from below appear to cause no damage to workshops, stockpiles etc (these things appear to protect the tiles as well) so the strategy of paving or utilizing everything appears to work well.