Device-to-device (D2D) communication has attracted a great deal of attention in the last few years due to its potential to enhance wireless network capacity and reduce energy consumption, among other benefits. Here, the problem of maximisation of the performance of a D2D network in a scenario in which D2D users share communication channels with users of a cellular network is investigated. Using stochastic geometry tools, the problems of maximisation of the performance metrics area spectral efficiency (ASE) and energy efficiency (EE) of the D2D network by adjusting the density, transmit power, and link throughput of D2D users are formulated and solved. The maximisation of ASE and EE is performed by imposing that the successful transmission probabilities of both D2D and cellular networks are not below given minimum acceptable levels. Based on the derived formulation, the effects of several parameters on the network performance are assessed. The study shows the existence of three possible operating regimes for the D2D network, according to the behaviours (increasing or decreasing) of ASE and EE when the quality of the D2D links increases. 1 INTRODUCTION Device-to-device (D2D) communication has been considered in the last years as one of the 5G wireless networks key technologies. In short, D2D communication allows nearby user devices to directly communicate with each other, that is, without having base stations involved in the message transmissions. Consequently, D2D links usually involve shorter communication distances, requiring reduced transmit power, causing lower interference, and leading to higher spectral efficiency transmission schemes, among other benefits, when compared to conventional cellular communication. Regarding spectrum usage, D2D devices can operate either in the in-band mode, or in the out-ofband mode [1]. In the former mode, D2D links use the cellular spectrum, while in the later, other bands (e.g. the unlicensed 2.4 GHz band) are used by D2D links. Under in-band mode, two sharing modes are possible: overlay mode, when D2D and cellular transmissions use orthogonal channels, avoiding interference between cellular and D2D links, and underlay mode, when cellular and D2D share the available channels, with D2D transmitting opportunistically. This is an open access article under the terms of the Creative Commons Attribution License, which permits use, distribution and reproduction in any medium, provided the original work is properly cited.