This paper introduces an optimal voltage control (OVC) framework for islanded microgrids (MGs) as a unified hierarchical control scheme, started from bus voltage set-points optimization at tertiary level, then effectively followed by secondary control, which controls the distributed energy resources via their primary level controllers. The distributed control structure is proposed here for both tertiary and secondary levels to benefit from higher reliability, avoidance of a single point of failure, and a relatively simple communication system. At the tertiary level, a new distributed voltage protocol, based on the Lyapunov theory, is proposed to optimize power losses and voltage profile deviations in the MG. The obtained optimal voltage references are passed to the secondary level, in which a modified distributed protocol (MDP) is utilized to ensure the OVC and dynamic stability. In addition, the proposed MDP can maintain the critical bus voltage against load changes until the next optimal set-point updates. The performance of the MDP is examined for different scenarios such as load changes and DGs plug and play operation in the MATLAB/Simulink environment.