hi!
Any stack that don't move will start entrenching automatically. It does not mind if they are on defensive or offensive. Both will entrench.
BUT!!! on offensive they will get out of their trenches and seek any enemy that enters their region, so they will not use and get the benefits of their entrenchment.
Only units on defensive/passive will benefit form thir entrenchments.
You can entrench both inside structures and outside. And you can have a stack inside an another outside entrenched. Whats more several stacks on the same region (inside or outside) will entrench separately and can have different entrenchment levels.
You can entrench up to level 8 if you have arty on the stack. If not they will entrench only up to level 4 (or maybe it was changed to 3 with the latest patches

Better check the updates document on your game installation folder

)
Also on the first years of teh war entrenchments are limited to lower values. Check the updates document.
To get that high level trenches a stack will need to remain on the region for several turns.
And be careful, if you move a stack to another region they will lose their trenches. A good trick is to let one unit digging/keeping the trenches. Later you can merge another stack with that unit already entrenched and all will occupy and benefit from the trenches.
To know what trench level a stack have look for a zigzagging icon on the upper right corner of the units panel, by the supply, activation and ammo icons. A number from 1 to 8 will tell you the level.
Also the stacks on map will have different sprites on their bases (sacks, palisades with guns) to represent their trench level.
On the battle reports the trench level is represented with more detail, on hundreds: a level 3 trench will figure like a trench value between 201 and 300.
Hope it helps
