This study investigates the performance of an optimal indoor environment in a campus classroom. The control system is able to regulate and balance the needs for illuminance, thermal comfort, air quality, and energy saving. By incorporating with Machine Learning and illumination algorithm associated with Internet of Things, wireless communication and adapted control, optimal energy saving and environment control can be achieved. Additionally, by using Video Image Detection to analyze the number of occupants and distribution in the classroom offers better energy optimization. In this study, the split-type air conditioning system has been used which is different from that in most literatures. About 30 tests are conducted and the occupant numbers range from 1 to 2 hours and each hour is 50 minutes. The class types include normal lecture and examination which shows completely different characteristics. The proposed AI agent contains the benefits not only for small or medium indoor space, but also for residences. In order to adjust the indoor illuminance, wireless and adjustable illuminance level LED were installed. Under the control of the illumination algorithm, the illuminance of each area of the classroom can be optimized according to the occupant distribution. The test results indicate that, by maintaining thermal comfort and air quality, when comparing with fixed setting point control 25 degrees, the average energy saving is 19%, and the average CO2 concentration is decreased by 21.3%. When comparing with setting point temperature of 26 degrees, the average energy saving is 15% the average CO2 is decreased by 12.9%.