Occlusion is the key and challenging problem in stereo matching, because the results from depth maps are significantly influenced by occlusion regions. In this paper, we propose a method for occlusion and error regions detection and for efficient holefilling based on an energy minimization. First, we implement conventional global stereo matching algorithms to estimate depth information. Exploiting the result from a stereo matching method, we segments the depth map occlusion and error regions into non-occlusion regions. To detect occlusion and error regions, we model an energy function with three constraints such as ordering, uniqueness, and color similarity constraints. After labeling the occlusion and error regions, we optimize an energy function based MRF via dynamic programing. In order to evaluate the performance of our proposed method, we measure the percentages of mismatching pixels (BPR). And we subjectively compare the results of our proposed method with conventional methods. Consequently, the proposed method increases the accuracy of depth estimation, and experimental results show that the proposed method generates more stable depth maps compared to the conventional methods.