The sale of a former school, which has stood empty for 16 years, has been hailed as a “victory for residents” following a row over housing plans.