Microfiltration and ultrafiltration are methods of removing colloidal impurities from water and wastewater. One of the major issues when dealing with the practical implementation of membranes is the reduction of water productivity as the foulants accumulate on the membrane surface or within the pores. Membrane regeneration by periodic backwashing is an effective method of reducing fouling; however, to date the timing and duration of the backwashing for effective fouling control is largely only empirically determined. In this manuscript, we present an optimal control formulation to determine the timing and duration for membrane regeneration by backwashing. In this formulation, we use the direction of the flow as the control variable and make predictions regarding the optimal protocol. We explicitly include irreversible attachment due to bacterial deposition and biofilm formation on the membrane and demonstrate that irreversible attachment of bacteria has important ramifications for the effective timing of hydraulic backwashes as well as the efficiency in producing clean water. In particular, we find that irreversible attachment and additional fouling due to exo-polymeric substance (EPS) production and biofilm formation decreases the maximum filtration volume. Additionally, as the effectiveness of membrane regeneration declines, the timing of the cycling is also altered. In general, including the role of EPS in biofouling substantially changes predictions of backwashing timing and implies important considerations for practical predictions.