New flats are set to be built in Wolverhampton city centre after a plan to convert a former factory and offices was approved.