How to turn your stock market losses into a tax-savings windfall