First, Newton's 3 laws of motion were already known, and Newton did not take credit for them. In his Principia, Newton wrote that the first two laws of motion were known to Galileo, and used by Galileo. Newton's introduction to mechanics appears to have been Descartes' Principia philosophiae, published 1644, and read by Newton in 1664 - the source of Newton's 1st law of motion. Newton credits the 3rd law to Huygens, Wren, and Wallis.
Later, Newton claimed to have developed his law of universal gravitation in 1665-1666 (the plague years), but this is not supported by his notebooks. It's very unlikely that Newton developed it before Hooke's suggestion that orbits could/should be explained by a central force law (in 1674). The first certain evidence we have for Newton having developed his law of gravitation is in 1684. Newton also claimed to have used the inverse square law of gravitation to calculate orbits in late 1679, but no such calculation has survived (and was already not available in 1684). Thus, we have a range of possible answers to your question of how long it took Newton to develop his law of universal gravitation:
20 years, from when Newton first turned his attention to mechanics (and orbital motion was a major motivation for him to do so), to his arrival at the law in 1684.
2 years, from 1664 to 1666 if we believe Newton's claim of 1665-1666.
Approximately 10 years, if we count the time from Hooke's central force law to Newton's law in 1684.
Approximately 5 years. Newton had certainly begun working on the problem by the end of 1679. 1679 is the most probably starting point for Newton's intensive work on the problem.
1 year. Newton began intensive work on the problem in 1679, and we believe Newton's claim of 1679.
There is an element of free choice in where we choose to count the years from. We don't know when Newton developed his law. Thus, we have a range of possible answers. (There are, of course, other combinations of start and end years other than the ones I have listed above.)
A short version of what we know of Newton's approach to the law of universal gravitation is in
and a longer version in
The development of Newton's laws (by others, as Newton himself noted) took place over a long time. This development is covered in