Wireless medium access control (MAC) and routing protocols are fundamental building blocks of the Internet of Things (IoT). As new IoT networking standards are being proposed and different existing solutions patched, evaluating the end-to-end performance of the network becomes challenging. Specific solutions designed to be beneficial, when stacked may have detrimental effects on the overall network performance. In this paper, an analysis of MAC and routing protocols for IoT is provided with focus on the IEEE 802.15.4 MAC and the IETF RPL standards. It is shown that existing routing metrics do not account for the complex interactions between MAC and routing, and thus novel metrics are proposed. This enables a protocol selection mechanism for selecting the routing option and adapting the MAC parameters, given specific performance constraints. Extensive analytical and experimental results show that the behavior of the MAC protocol can hurt the performance of the routing protocol and vice versa, unless these two are carefully optimized together by the proposed method.