Here is a snippet from Intuit.
"short-term losses are first deducted against short-term gains, and long-term losses are deducted against long-term gains. Net losses of either type can then be deducted against the other kind of gain."
From how I understand it, if the stock that you lost money on is classified as "long term capital loss" and the rental property is also classified as a "long term capital gain," you should be able to offset the gain with the loss.
I am NOT a tax professional. I suggest you check with a tax person to confirm my answer.