The very basics would be to first decide what data format you're using to store the state of your tiles. Either an array or tilemap would work well.
When placing a building, check all relevant tiles/cells relative to the cursor/placement position to see if they are valid. If not, then do nothing or display an error. If all valid, then place the building and update the tile/cell data it now occupies.
If using arrays, recording the uid of the building object is one way to keep track of what is currently occupying any cell. If using tilemap, the tile number itself could naturally identify the building.