Yes, you can offset the gain on sale of the building against the loss carryover. Hence you will not owe any tax on the gain on sale of the building.
Capital gain is calculated as Sales price less adjusted cost basis(which is cost minue the accumulated depreciation). If there is a gain on sale than gain to the extent of accumulated depreciation is taxed at higher rate. But in this particular case the gain will be offset by the loss carryover and hence, there will be no tax.
Let me know if you have any question.
Please note: This advice is provided with the understanding that all the relevant facts have been provided by you. Any change in facts might affect the advice given and hence may not be relied on in such cases. Nothing contained in this reply was intended or written to be used, can be used by any taxpayer, or may be relied upon or used by any taxpayer for the purposes of avoiding penalties that may be imposed on the taxpayer under the Internal Revenue Code of 1986, as amended.
By recapture of accumulated depreciation - part of the gain gets taxed at a higher rate. The accumulated depreciation is not added back to the income.
So if there is no gain after the offset of the gain with carry over losses - there will be no recapture of accum depreciation.
So yes, the carry over losses will take care of that too.