There is an acute need to evaluate the energy consumption of buildings in response to climate change. The “occupant” factor has been largely overlooked in building energy analysis. This research aims at investigating occupancy existence in the office environment using a hybrid artificial neural network with metaheuristic algorithms for improved energy management. It proposes and compares three classification models, namely particle swarm optimization (PSO), gravitational search algorithm (GSA), and hybrid PSO-GSA in combination with the feedforward neural network (FFNN). The inputs to these models are data related to temperature, humidity, light, and carbon dioxide emissions. Two data sets are used for testing the models while the office door is open and closed. The capabilities of the optimized models are evaluated using best, average, median, and standard deviation of the mean squared error. Most of the performance metrics indicate that the FFNN-PSO-GSA model exhibits better performance compared to the other models using the two datasets. The proposed model yields a classification accuracy ranging between 98.47-98.73% using one predictor (i.e., temperature). Besides, it yields an accuracy ranging between 85.45-94.03% using temperature and CO2 predictors. It can be concluded that the FFNN combined with PSO and GSA algorithms can be a useful tool for occupancy detection modeling.