The Ebrie lagoon system comprises the lagoons of Ebrie, Potou, and Adjin. In the villages that are around the edges of this lagoon system, there are several farms, such as pigsty, poultry and enclosures. Thus, the excessive use of manure on farmland creates a serious environmental problem. The excessive manure discharge that crops need as fertilizer leads to excess manure in these fields. As Ivory Coast is a country where it rains a lot, rainwater drains these excessive quantities from the surface into the Ebrie, Potou, and Adjin lagoons, where they pollute the water, feed the algae, and harm the fish. Our first aim is to develop an optimization method based on ordinary differential equations (ODE) to determine the right field at the right time for environmental damage to be limited. We collect current data in a region of topologically connected lagoons and their adjacent farmlands. To numerically solve this mathematical problem, the software used is Matlab. Using real data, this solution improves the quality of the water by drastically reducing in a continuous-time, the quantity of manure and its principal components such as nitrogen, phosphorus, and potassium.