Restricted Access Window (RAW) and group-based media access are new features that are exploited by IEEE 802.11ah standard to resolve massive access problem in Internet of Things (IoT) applications. Nevertheless, inefficient device grouping and inappropriate contention resolution in a RAW may still result in collisions and consequently lead to degradation of QoS, energy efficiency, and channel utilization. In existing works, contention resolution schemes schedule all failed devices to retransmit in the next slot of the RAW, which increases the probability of collisions. In this paper, we propose a new retransmission scheme that allows the collided devices of each RAW slot to have another transmission chance in one of the next µ upcoming slots, randomly. We represent the proposed retransmission method via a probabilistic model and formulate a problem based on it, to adjust the number of slots of each RAW with the aim of increasing overall energy efficiency and overall channel utilization regarding delay constraint of devices. Solving the formulated problem, a meta-heuristic algorithm is used to adjust the number of RAW slots and so the size of each RAW regarding the results of the device grouping algorithm. To better exploit the capabilities of the proposed idea, we suggest a load-aware and distance-based device grouping algorithm that not only considers the hidden node problem, but also attends to the load balance of the groups. Simulation results show that the proposed retransmission and RAW adjustment scheme alongside the proposed device grouping algorithm, improve energy efficiency and channel utilization by 25 % and 17 % respectively, and reduce the access delay by 31 % in average, compared to the previous retransmission method.