In this study, integration of three important concepts of distributed generation, D-FACTS devices, and microgrids are evaluated. The performance of a microgrid is dependent on its location, capacity, and placement of DG units and D-FACTS devices. In this paper a new method is proposed to simultaneously determine the optimal number, location, and capacity of DG units and D-STATCOM devices and optimal boundaries of electrical islands in the independent mode of microgrids. The main objective is to minimize the economic costs. The optimal locations of DG units and D-STATCOM devices should be determined to maximize the DG capacities with minimum loss in the best voltage profile and in the grid-connected mode of microgrids. Moreover, this locating besides simultaneous determination of island boundaries makes it possible to supply the maximum load in the islanded mode operation. To meet the mentioned goals, the PSO algorithm and MATLAB software are used. Analyzing the obtained results shows that the proposed method has suitable capability in optimal operation and cost management of distribution network planning.