In order to implement the inverse kinematics of a 6R robot (with spherical wrist), you need to use a technique called kinematic decoupling. Kinematic decoupling is when you separate the task of orienting the end effector with the task of translating the end effector.
The book that I think talks about this well is
Robot Dynamics and Control
Second Edition, W. Spong, Seth Hutchinson, and M. Vidyasagar.
For this next part, I am assuming you have learned about D-H parameters already (and therefore have developed the forward-kinematics frame transforms for your 6R robot). If not, the Wikipedia page is a great source on the subject.
First 3 Joints Analysis
When looking at a 6R robot, and as you already mentioned, there is a spherical wrist at the end effector (ee). This sperical wrist determines the orientation of the ee and therefore all of the calculations for solving for the location of the ee can be solved pretty easily. This is because the first 3 joints, or 3 equations, all contribute to the location of the center of the wrist. You know the location of the wrist by doing the inverse transform of the ee along the local Z-axis by the robot's physical offset. (This is known as the approach vector, which is the Z-component of the rotation matrix, also known as the 3rd column unit vector. The offset distance along this vector is a constant known value that can be changed to somebody's needs and the math does not change.)
You can then solve for the first 3 joint angles by solving the X-Y-Z equations for the location of the center of the wrist, which would be frame transforms T0-1 to T2-3 multiplied together. These calculations may result in multiple solutions, so you need to be mindful of including all possible solutions.
Spherical Wrist Analysis
Once you have decided which 3 joint values you want for the first 3 joints, you can then solve for the wrist. Since you know the frame transforms T3-6 from your D-H table, you can then look at the rotation component of the frame transform. I don't remember off the top of my head what it looks like, but there are specific elements in the matrix that have fewer symbolic terms involved in the mathematical definition which allow you to systematically solve for the rotations of the last 3 joints.
After a quick google search, I found resources on how to solve spherical wrists with pretty pictures. This one also happens to show how to do the first 3 joints as well. I don't want to take credit for other people's work, but there are many presentations out there that explain this out fully pretty well. I also didn't want to make this a simple link answer, but rather explain what is going on, then share a reference link.
I am writing this without all of my books in front of me, but hopefully it gives you more of a direction. You just need to understand kinematic decoupling and this problem will look a lot simpler to you. I would happily share a pdf of a book, but, let's just say I don't know how legal that would be... LoL hope that helps
(If this answer helped you, a vote up or green check-mark is greatly appreciated).