Node localization is essential to most applications of wireless sensor networks (WSNs). In this paper, we consider both range-based node localization and range-free node localization with uncertainties in range measurements, radio range, and anchor positions. First, a greedy optimization algorithm, named sequential greedy optimization (SGO) algorithm, is presented, which is more suitable for distributed optimization in networks than the classical nonlinear Gauss-Seidel algorithm. Then a unified optimization framework is proposed for both range-based localization and range-free localization, and two convex localization formulations are obtained based on semidefinite programming (SDP) relaxation techniques. By applying the SGO algorithm to the edge-based SDP relaxation formulation, we propose a second-order cone programming (SOCP)-based distributed node localization algorithm. Two distributed refinement algorithms are also proposed by using the SGO algorithm to nonconvex localization formulations. The proposed localization algorithms all can be implemented partially asynchronously in networks. Finally, extensive simulations are conducted to demonstrate the efficiency and accuracy of the proposed distributed localization algorithms.