In wireless sensor networks, where energy is scarce, it is inefficient to have all nodes active because they consume a non-negligible amount of battery. In this paper we consider the problem of jointly selecting sensors, relays and links in a wireless sensor network where the active sensors need to communicate their measurements to one or multiple access points. Information messages are routed stochastically in order to capture the inherent reliability of the broadcast links via multiple hops, where the nodes may be acting as sensors or as relays. We aim at finding optimal sparse solutions where both, the consistency between the selected subset of sensors, relays and links, and the graph connectivity in the selected subnetwork are guaranteed. Furthermore, active nodes should ensure a network performance in a parameter estimation scenario. Two problems are studied: sensor and link selection; and sensor, relay and link selection. To solve such problems, we present tractable optimization formulations and propose two algorithms that satisfy the previous network requirements. We also explore an extension scenario: only link selection. Simulation results show the performance of the algorithms and illustrate how they provide a sparse solution, which not only saves energy but also guarantees the network requirements.