Basically the rules state that if your property is producing income you can claim expenses (like interest on mortgage, rates, maintenance etc) on it, and you have to pay capital gains if you sell at a higher price than what you paid for it plus buying and selling costs.
If you live in it (and it does not produce any income) you do not pay any capital gains when you sell but also cannot claim expenses on it.
If you live in it as your primary residence, and then rent it out because you have to move else-where due to certain circumstances and the property remains your primary residence (ie you may have had to relocate due to work and are renting in this new location), you have 6 years in which to sell it and not be liable to pay any capital gains.
If you live in it for part of the time and rent it out during other times and you don't qualify for the above rule, then you are liable to pay capital gains based on the periods you have rented out the property. So you would need to estimate the value of the property for each point in time you move in and out to work out how much capital gain you would be liable for (it would be good to get an appraisal or valuation at these points in time).
If you live in the property and have paying house mates or use part of the property to produce income, you will have to work out what portion of the house is income producing and then use this percentage to work out the proportion of expenses you can claim against the income. You would also use this percentage to work out the capital gains tax you have to pay if you sold it.
For example, say you have a 3 bedroom house and rent out 1 bedroom and the normal rent for the whole house was $300 per week and you rented one bedroom for $100 per week, you could estimate that the proportion producing the income is 33.33%. Then you could claim 33.33% of all your property related expenses as a tax deduction. Also, say if you bought the house for $300,000 and sold it for $450,000 about 5 years later, your capital gains liability could be worked out as such (ignoring all buying and selling costs for simplicity):
Profit on sale: $450,000 - $300,000 = $150,000
Profit x Portion of Property Producing Income = $150,000 x 33.33% = $50,000
Capital Gain Liability (including discount for holding asset 12+ months) = $50,000 x 0.5 =$25,000.
You would then multiply your marginal tax rate by the $25,000 to work out how much capital gains tax you would have to pay.