Iron golems are 1.4 blocks wide and 2.7 blocks tall, meaning that you can have a wall around your house with gateways 2 blocks off the ground so iron golems can't get out.
Another way is to have walls that have a 1-block gap in between them so you can get through but iron golems can't.
Finally, you can build the iron golem inside your house or if your house is surrounded by a natural barrier like a river, you can build it outside and wall off the rest of the sides.
All these designs are not that great though because skeletons can still shoot iron golems from outside the wall. What you want to do is to have a villager in your house or hidden underground to anchor the iron golem there. Works pretty well but if the iron golem keeps chasing mobs it might eventually get out.
Overall, it would cost less to just build a wall around your house and just leave it like that.