In this paper, we propose and analyze a novel optimization model to maximize the lifetime of Internet-of-Things (IoT) networks, including the Low Power Wide-Area Network (LPWAN) based Sigfox star networks and Time Slotted Channel Hopping (TSCH) mesh networks. An IoT cloud manages the IoT network adapting to sensed phenomenon changes in the deployment area retrieved from peered cloud-based environmental monitoring systems. While increasing the number of paths for IoT devices to cloud communication increases reliability, it also comes at the expense of increased energy consumption. We consider an optimization problem to determine the best redundancy level to be applied in the IoT network such that the lifetime is maximized while achieving the quality-of-service (QoS) requirements in the presence of unreliable sensing environments. Our model is generic and easily adaptable to a given IoT technology by considering the technology's devices, environmental, and protocol specifications while spanning single-hop, multi-hop, short-range, and long-range IoT technologies. We formulate the tradeoff between energy conservation vs. reliability of an IoT network as an Integer Non-Linear Programming (INLP) optimization problem. The feasibility of our approach in maximizing the lifetime of IoT networks for both the star and mesh network topologies is demonstrated using SigFox and TSCH as representative technologies, respectively. We conduct an extensive comparative performance analysis demonstrating that our model outperforms contemporary baseline models in both SigFox and TSCH IoT network technologies.