Cyber-physical system (CPS) is a concept that integrates every computer-driven system interacting closely with its physical environment. Internet-of-things (IoT) is a union of devices and technologies that provide universal interconnection mechanisms between the physical and digital worlds. Since the complexity level of the CPS increases, an adversary attack becomes possible in several ways. Assuring security is a vital aspect of the CPS environment. Due to the massive surge in the data size, the design of anomaly detection techniques becomes a challenging issue, and domain-specific knowledge can be applied to resolve it. This article develops an Aquila Optimizer with Parameter Tuned Machine Learning Based Anomaly Detection (AOPTML-AD) technique in the CPS environment. The presented AOPTML-AD model intends to recognize and detect abnormal behaviour in the CPS environment. The presented AOPTML-AD framework initially pre-processes the network data by converting them into a compatible format. Besides, the improved Aquila optimization algorithm-based feature selection (IAOA-FS) algorithm is designed to choose an optimal feature subset. Along with that, the chimp optimization algorithm (ChOA) with an adaptive neuro-fuzzy inference system (ANFIS) model can be employed to recognise anomalies in the CPS environment. The ChOA is applied for optimal adjusting of the membership function (MF) indulged in the ANFIS method. The performance validation of the AOPTML-AD algorithm is carried out using the benchmark dataset. The extensive comparative study reported the better performance of the AOPTML-AD technique compared to recent models, with an accuracy of 99.37%.