An islanded microgrid (MG) including low-inertia converter-based distributed generations (DGs) is subjected to instability. The virtual inertia concept was proposed to alleviate the stability issues by imitating the synchronous generators behavior. This paper spotlights on the optimization of virtual synchronous generator (VSG) parameters and virtual impedances (VI) in islanded MGs using particle swarm optimization (PSO). A smallsignal model for MG is developed at first. The permissible ranges of virtual inertia (J) and virtual damping (D) based on MG small-signal stability are scrutinized afterwards. Moreover, VI are considered to lower the reactive power mismatch between converters. Finally, considering the permitted intervals for these parameters, an optimization method and objective function are defined to calculate VSG parameters and VI in the islanded MG. The proposed optimization method enhances the smallsignal stability of the MG, decreases the current overshoot and minimizes reactive power mismatches. Simulation results drawn by the "VSG + VI" control include three scenarios. The effectiveness of the proposed "VSG + VI" control method in comparison with "droop" control, "droop + VI", "non-optimal VSG + VI", and "VSG " is verified through simulation studies.