Stocks close lower, but post biggest monthly gains since June