This study describes the design and construction of a wastewater treatment package using an electrocoagulation system and examines the optimization of the system. For optimization, the factors including number of electrodes, gap between electrodes, current density, time and pH were optimized using the Design-Expert Software. According to response surface tests, the optimum range was selected to maximize the removal efficiency of chemical oxygen demand, total dissolved solids, and biological oxygen demand. This range for current density was between 49.8 and 80 A/m2, the process time was from 9 to 15 min, and the pH between 6.5 and 8, the number of electrodes was 2 pairs and the gap between the electrodes was 1 cm. It was observed that with increasing the current density, time, number of electrodes and the electrode gap, energy consumption increases and pH changes do not affect energy consumption. The optimum range in which the treatment efficiency is above 80% and the energy consumption is less than 5 kWh/m(3) of the sewage is current density between 49.8 and 63 A/m(2), time between 9 and 11 min, pH 6.5-8, the number of electrodes 1 pair and the gap between the electrodes, 1 cm. In this optimal range, the energy consumption per one cubic meter of wastewater is between 4.5 and 5 kWh.