You may be able to exclude from income any gain on the sale of your main home up to a limit of $250,000 ($500,000 on a joint return in most cases).
To claim the exclusion, you must meet the ownership and use tests. This means that during the 5-year period ending on the date of the sale, you must have:
Owned the home for at least 2 years (the ownership test), and
Lived in the home as your main home for at least 2 years (the use test).
If you qualify for the capital gain exclusion, you do not have to report the gain on the sale of your personal residence on your federal tax return unless the gain on the sale was greater then the exclusion, you rented the house out during the time you owned it, or you received a Form 1099-S for the sale of the home.
See IRS Publication 523 Selling Your Home for more information - http://www.irs.gov/pub/irs-pdf/p523.pdf
Some of the closing costs may be deductible as itemized deductions. Most expenses at closing on the purchase or refinance of a home are added to the cost of a home and are not deductible but are added to the cost basis of the home. There are a few exceptions - the following would be deductible:
1. Interest paid at the time of purchase (the charge at closing would normally be done for interest up to the date of first payment.) This is sometimes included in the 1098 from the new lender.
2. Real estate taxes charged to you and not reimbursed by seller
3. Points or origination fees. On a refinance they need to be amortized over the life of the loan unless the points were used to improve your main home.
4. Private mortgage insurance costs but, if prepaid, only the amount allocable to this year based on an 84 month amortization.
Title fees, real estate commissions, documentary stamps, credit report costs, costs of an abstract, transfer taxes, attorney fees, etc. are not deductible, but are added to the cost of the property.