Deep Learning (DL) models can be trained to automatically learn the underlying features of the traffic patterns in IoT networks to detect complex botnet attacks. However, the performance of a neural network model largely depends on the set of hyperparameters that is used for the model development. In this paper, an algorithm is proposed to determine the optimal set of hyperparameters (the numbers of hidden layers and hidden units, the learning rate, the optimiser, the activation function, the batch size, and the number of epochs) for efficient DL-based botnet detection in IoT networks. The DL models employ a Deep Neural Network (DNN) architecture for binary and multi-class classification. DNN-based botnet detection models are developed and experiments are performed with the Bot-IoT and N-BaIoT datasets to validate the effectiveness of the hyperparameter optimisation method. Experiment results showed that the proposed method produced DNN models that achieved high botnet attack detection rates, low false alarm rates, and near real-time computation speed.