Structural transformation and charge transfer induced ferroelectricity and magnetism in annealed YMnO3