Research is continuing to increase the efficiency of energy used by buildings due to environmental problems such as greenhouse effect. The need for minimizing the energy used by the lighting is becoming more and more important because lighting energy is responsible for a large portion of the energy used by buildings. In addition, a method of applying a Cyber Physical System(CPS) to existing buildings is being studied in order to efficiently maintain the buildings. In this paper, we utilize the CPS infrastructure to be built in a building to optimize the energy of the lighting used by the building. We propose a Self-error correction Occupancy Counting Algorithm(SOCA) by applying a self-error correction algorithm to the existing occupancy measurement algorithm in order to measure the occupancy of accurate buildings by utilizing the building IoT(Internet of Things) infrastructure called CPS. In addition, we propose an Adaptive Dimmable Lighting Energy Management Scheme(ADLS) to maximize the user's satisfaction and to optimize the lighting energy of the building by using the accurately measured occupancy. We applied the proposed algorithms to the space to evaluate the energy conservation performance of buildings. As a result of applying it to various spaces, energy saving performance up to 70% was obtained. The effectiveness of the proposed algorithm is evaluated by modeling several spaces and simulating the effectiveness of the proposed algorithm.