By incorporating reconfigurable intelligent surface (RIS) into communication-assisted localization systems, the issue of signal blockage caused by obstacles can be addressed, and passive beamforming can be employed to enhance localization accuracy. However, existing works mainly consider ideal channels and do not account for the effects of realistic impairments like carrier frequency offset (CFO) and phase noise (PN) on localization. This paper proposes an iterative joint estimation algorithm for CFO, PN, and user position based on maximum a posteriori (MAP) criterion and gradient descent (GD) algorithm. Closed-form expressions for CFO and PN updates are provided. The hybrid Cram\'{e}r-Rao lower bound (HCRLB) for the estimation parameters is derived, and the ambiguity in CFO and PN estimation is analyzed. To minimize the HCRLB, a non-convex RIS shift optimization problem is formulated and is transformed into a convex semidefinite programming (SDP) problem using the technique of semidefinite relaxation (SDR) and Schur complement. After optimizing the RIS phase shift, the theoretical positioning accuracy within the area of interest (AOI) can be improved by two orders of magnitude, with a maximum positioning root mean square error (RMSE) lower than $\rm 10^{-2}m$.