Wireless sensor network (WSN) is a key technology trend in emerging internet of things paradigms which are commonly used for application areas such as smart-cities, smart-grids, wearables, and connected health. There is a wealth of literature which considers various cluster-based routing protocols such as LEACH, HEED, and UHEED where these protocols are compared in terms of the network lifetime and/or the total number of packets successfully received by the base station under various operational conditions. While existing studies present various approaches to form WSN clusters in the most efficient way, various parameters are manually-assigned their values such as the radius of the cluster, the number of nodes in the cluster, and the number of clusters that should be formed to reach the base station. The choice of correct parameters is essential for reaching the most efficient configuration, however existing studies do not specify a systematic way for tuning these parameters. In other words, the optimization of cluster-based WSNs through fine tuning of related system parameters is not considered in the existing studies. We believe that presenting a generic approach to tune the parameters of clustering algorithms in order to optimize the performance metrics of WSNs is a significant contribution. In this study a systematic and an efficient method is presented to tune the parameters of clustering and routing protocols. Instead of brute force, or trial and error approaches, simulated annealing and K-beams algorithms are adopted together with discrete event system simulator OMNET++ with Castalia Framework. Results are presented comparatively with brute force approach in order to show the efficiency of the new approach in finding the optimum configuration in terms of energy efficiency as well as the rate of successfully received packets.