it does cost coins to upgrade your farm and you can do it at any time. It also requires a specific number of neighbors. Here is what I think are the costs:
14x14: 10,000 coins, minimum 8 neighbors
16x16: 25,000 coins, minimum 10 neighbors
18x18: 50,000 coins, unsure what neighbor requirement is
20x20: 75,000 coins, unsure what neighbor requirement is
You have to upgrade in order, you can't go immediately to 20x20. You spend the 10,000 coins, then the 25,000 coins, etc.