I'm not 100% certain but this is what I believe the rules to be.
In calculating your allowable acquisition costs you cannot claim mortgage costs (mortgage opening fee, notary costs that relate to mortgage deed, tax relating to mortgage etc).
You can however increase you acquisition/purchase costs by a coeficiente de actualizacion which from 2003 until 2010 is approx 1.125 - sorry I don't have exact rates to hand. This is meant to increase your historical acquisition cost to present value. So multiply your acquisition/purchase cost by 1.125 approx
You can also deduct costs of disposal such as estate agent fees etc to arrive at a net proceeds of sale.
To claim roll-over relief there are some conditions:-
1 - Must be resident
2 - Have lived in the house for 3 years
3 - Buy a main residence within 2 years
The tax relief is based on the proportion of the total sales proceeds re-invested in the new home. So if you only re-invest half the proceeds of sale then only half is deferred.
If you are 65+ then I believe the gain is tax free and there is no need to re-invest.