The oil and gas industry is changing. The drive towards cleaner and safer operations is becoming increasingly important. Researchers are looking for more efficient and accurate ways to detect faults that could lead to environmental and sustainability issues. This study aims to enhance the safety and sustainability of the oil and gas industry by improving existing artificial intelligence approaches to automate monitoring and detection of malfunctions. This article explores the application of deep neural networks for anomaly detection in monitoring oil and gas flow in natural flow offshore wells, proposing an innovative approach that takes advantage of the power of Genetic Algorithms and Gated Recurrent Units (GRU). The study aims to enhance the safety and sustainability of the oil and gas industry by leveraging artificial intelligence to automate the monitoring and detection malfunctions. Utilizing a comprehensive dataset from the 3W Petrobras project, which includes real-time data from 21 wells collected between 2012 and 2018, the research focuses on detecting various anomalies such as abrupt increases in basic sediment and water, spurious closures of downhole safety valves, severe slugging, flow instability, rapid productivity loss, quick restrictions in the production choke, scaling, and hydrate formation in production lines. The methodology integrates Long Short-Term Memory (LSTM) networks and GRU backbones with genetic algorithms to optimise model performance. Several hyperparameter optimisation tools were explored innovatively, focusing mainly on Genetic Algorithms, and it was possible to obtain an algorithm with 2 stacked GRU with better comparative performance compared to what is reported in the literature and producing an F1 equal to 0.97. The findings demonstrate the potential of AI to improve real-time anomaly detection, thereby reducing operational risks and contributing to the industry's transition towards greener practices. It also underscores the importance of open data and collaborative efforts in advancing AI applications in the oil and gas sector, aligning with the United Nations' Sustainable Development Goals to mitigate climate impact and promote responsible consumption and production.