I know this is possible because I have seen it done in Korean Defense 2. The result for those who don't know is that the unit is invincible but can still be attacked.
I have tried some stuff in Starforge and Xtra edit but no luck yet. I suspect an editor like scmdraft is needed.
EDIT:
Doh the first thing I try after posting this works. If anyone else wants to know: In Starforge, for the unit you want, set the unit settings to 0 max hp. In the game it will then have 0 / 1 hp, instead of 0 / 0.