Farming fences can be crafted if "Farming" is unlocked on the Tech tree or can be bought for 4 gold coins per fence at the Goblin Shop.
Placing 5 fence horizontally next to each other creates a farmhouse, placing additional fences will expand the size of the farm so more animals can be held in it.
Animals caught by Trap can be stored in the farm. Sheep and llamas can be sheared for their wool by clicking on them and selecting "shear", though this requires the scissors tools. Scissors can be crafted once farming is unlocked.
A pair of animals will breed additional ones if left in the farm.