A unit can enter and garrison an unoccupied building if it can move into base contact with the building during the Movement phase. Some units simply cannot enter buildings – the members of the regiment are just too big – unless differently specified, only infantry, monstrous infantry, war beasts, monstrous beasts and swarms can garrison a building. Remember that war machines can also be deployed in buildings. Units cannot garrison a building in the same turn in which they have marched – swiftly getting a formation of ranked up troops into a building is not easy.
When a unit garrisons a building, you'll normally find that there's not enough room for the models in or on the structure (or that placing them in the building just looks silly). It's perfectly acceptable to place a representative model from the unit in, on or next to the building to remind you that the unit is inside (standard bearers are the best for this!), and place the rest of the unit aside from the battlefield. The main thing you're trying to achieve is to leave a recognisable reminder as to the building's occupants for both you and your opponent as the game goes on.