The impact of earthquakes on surface and underground structures has been always an important and significant issue and has attracted the attention of mining and civil engineers. Engineers consider the effects of seismicity on surface and underground structures and try to deal with them before an earthquake causes irreparable damage. This issue is of special importance since Iran has many mines, both metallic and non-metallic mines (surface and underground) located on the seismic belt of the Alps. One of the most important effects that an earthquake can have on underground structures is to damage foundations in room and pillar mines. The main purpose of this study is to optimize the width of the pillars according to an optimum safety factor at different depths and because this mine has a slope of 8 to 12 degrees, the layer is considered horizontal but due to the width of the slope affects the depth. Optimization of the width of the foundations has been discussed in different depths. Finite difference numerical method using FLAC3D software is utilized for the analyses. Ultimately, the relationship between safety factor, layer depth and width-to-height pillar ratio were presented for static and dynamic conditions. Optimal widths in static conditions at depths of 80, 120, 160 and 200 meters were obtained 12, 14, 15 and 16 meters, respectively, and the optimal widths under dynamic conditions at the mentioned depths were obtained 15, 17, 17 and 18 meters.