Electrical and optical characterization of Er-implanted Si: The role of impurities and defects