Clock synchronization and localization are two fundamental problems in Wireless Sensor Networks (WSNs). Joint synchronization and ranging have been shown to significantly improve their accuracy. However, most existing work assumes that the recorded timestamps at all network nodes have the same error statistics, regardless of their received Signal-to-Noise Ratio (SNR). This model is less realistic because the timestamp recorded from a low-quality signal, such as a low SNR, could suffer higher errors than those with higher SNRs. This paper proposes a Weighted Least Square (WLS) solution for joint synchronization and ranging in WSNs. A more practical timestamp model is introduced that considers the impact of received signal quality on timestamp measurement errors. Based on the Received Signal Strength Indicator (RSSI), a weighting coefficient matrix is constructed for the WLS algorithm. Cramér-Rao Lower Bound (CRLB) is derived to provide a baseline for different algorithms. Simulation results show that the accuracy of the proposed algorithm is considerably improved, compared to the conventional Least Square (LS) solution, and in many cases approaches the CRLB. For example, the proposed WLS solution is over 10% more accurate than the LS counterpart in estimating the clock skew and clock offset of the nodes in the WSN comprising four anchor nodes and one sensor node. In addition, the computational complexity of the proposed WLS algorithm is shown to be only slightly increased compared to that of the conventional LS algorithm. For example, the computation of the former is approximately 6.4% more complex than that of the latter for a WSN of 10 anchors and one sensor. This makes the proposed WLS solution especially suitable for the joint synchronization and ranging problem in a dense WSN where the number of anchors and the number of timestamp transmissions between nodes are large.