Determining the optimum excavation sequence in mining or civil engineering requires using stress analysis methods to repeatedly solve large models. Time consuming preparation of the model and lengthy computations, often measured in days, can have major impacts on successful ongoing operation of an underground mine, where stope failures can cost millions of dollars and perhaps result in closure of the mine. Widespread acceptance of new tunneling methods such as NATM which depend heavily on numerical stress analysis tools and the fact that the effects of excavation at the face of the tunnel are distinctively three dimensional necessitates the use of 3D numerical analysis of these problems. A framework was developed to facilitate efficient modeling of underground excavations and to create an optimal 3D mesh by reducing the number of surface and volume elements while keeping the result of stress analysis accurate enough at the region of interest, where a solution is sought. Fewer surface and volume elements means fewer degrees of freedom in the numerical model. The reduction in number of degrees of freedom directly translates to savings in computational time and resources. The mesh refinement algorithm is driven by a set of criteria that are functions of distance and visibility of points from the region of interest and the framework can be easily extended by adding new types of criteria. A software application was developed to realize the proposed framework and it was applied to a number of mining and civil engineering problems to investigate the applicability, accuracy and efficiency of the framework. The optimized mesh produced by the framework reduced the time to solution significantly and the accuracy of the results obtained from the optimized mesh is comparable to the accuracy of the input data for mining engineering problems.