The Internet of Things (IoT) has been envisioned as an enabler of the digital transformation that can enhance different features of people's daily lives, such as healthcare, home automation, and smart transportation. The vast amount of data generated by a massive number of devices in an IoT system could lead to a severe performance problem. Edge cloud computing and network function virtualization (NFV) technologies are potential approaches to improve the efficiency of resource use and the flexibility of responsive services in an IoT system. In this paper, we consider the joint optimization problem of gateway placement and multihop routing in the IoT layer, the problem of service placement in the edge and cloud layers of an NFV-enabled IoT system in edge cloud computing (NIoT). We propose three optimization models (i.e., GMO, SP1O, SP2O) that allow an IoT service provider to find the optimal deployment of gateways, the optimal resource allocation for service functions, and the optimal routing according to a cost function with a performance constraint in a NIoT system. We then develop three approximation algorithms (i.e., GMA, SP1A, SP2A) for tackling the problems in a large-scale NIoT system. The evaluation results under a set of scenarios with various topologies and parameters show that the approximation algorithms can obtain results close to the optimal solution with a significant reduction in computation time. We also derive new insights into the strategy for an IoT provider to optimize its objectives. Specifically, the results suggest that an IoT provider should select an appropriate service placement strategy with regard to a charging agreement with an NFV infrastructure provider, and only deploy service functions with a strict delay requirement on the edge of networks for optimizing its cost.