IEEE 802.11ax as the newest wireless local area networks (WLANs) standard brings enormous improvements in network throughput, coverage and energy efficiency in densely populated areas. Unlike previous IEEE 802.11 WLAN standards where power saving mechanisms have a limited capability and flexibility, 802.11ax comes with a different mechanism called target wake time (TWT) where stations (STAs) wake up only after each TWT interval and different STAs can wake up at different time instance depending on their application requirements. As an example, for a periodic data arrival occurring in IoT applications, STA can wake up by following the data period and go to sleep mode for a much longer time, and STAs with high traffic volume can have shorter TWT interval to wake up more frequently. Moreover, as multiuser transmission capability is added to 802.11ax, multiple STAs can have the same TWT interval and wake up at the same time, and hence there is a great opportunity to have collision-free transmission by scheduling multiple STAs on appreciate TWT intervals to reduce energy consumption and also increase network throughput. In this paper, we investigate the problem of STAs scheduling and TWT interval assignment together to reduce overall energy consumption of the network. We propose an algorithm that dynamically selects STAs to be served and assigns the most suitable TWT interval given STAs' traffic and channel conditions. We analyze our algorithm through Lyapunov optimization framework and show that our algorithm is arbitrarily close to the optimal performance at the price of increased queue sizes.Simulation results show that our algorithm consumes less power and support higher traffic compared to a benchmark algorithm that operates randomly for TWT assignment.