There are three relevant factors to lay an eye upon when it comes down to decide if you want to rent or buy a home: relative cash flow (i.e. rent cost or monthly mortgage payments), planned length of living in the property, and value appreciate or depreciation rate.
The third factor is only an estimation and private persons should check appropriate tables for obtaining an estimate of the price variation in a concrete region. Traditionally we could find such tables in local newspapers, which published it periodically. In our modern times, it is easier to look up in the internet.
The analysis does not consider utility costs as a relevant factor, since we consider it to be the same in both cases. We do consider however that the insurance cost can be significantly differ in each case. Tenants should also pay a renter’s insurance, but this kind of insurance is relative inexpensive.
Opportunity costs are also implicitly dealt with. They are included in the present value of the real estate property. As the words imply, opportunity costs are the cost in terms of foregoing alternatives. Imagine that you have the necessary amount of money on your bank account to buy a home (without a mortgage). What is you better bet – to invest the money and rent the property or to buy the property with the cash in hand? It may sound a strange idea to take a mortgage (you are actually taking a credit) having money on the bank. However, consider that you perhaps can devise a good business alternative for your money and that mortgages are normally rather cheap credit. This scenario would broaden the amount of cash at your disposition, and you would end up earning some dollars.
In this analysis you will also include all three essential factors above. The value of the real estate property that you buy with a mortgage upon it can also increase. You can free up some cash (improve your cash flow). Of course, this only makes a sense if you plan to stay for some years on this property.
One point that many forget in their calculations is the inflation rate. Prices will necessarily vary in the term of the rent or amortization of the property. Having your money invested in a property is a good way of protecting your assets against this devaluation of the money (or increasing of prices, what actually comes down to be the same thing).
Summarizing: if the appreciation rate or the real estate is above inflation, it is normally better to buy. If it costs every month more or less the same, it is better to buy. For short terms it is better to rent. You can save taxes both ways: buying or renting. In the long term the tax costs are more or less the same.