Its actually pretty simple, and you''ll probably kick yourself when you see the solution for not realizing it earlier.

You have a point (x1, y1) that you want to rotate by angle theta around another point (x2, y2).

First translate both points by (-x2,-y2). This places your rotational axis point at (0,0), but keeps the relative locations the same.

Now do the rotation as you stated:

x1'' = x1*cos(theta) - y1*sin(theta)

y1'' = x1*sin(theta) + y1*cos(theta)

Now translate both points by (x2, y2). The rotational axis point is back where it started, and the point you wanted to rotate is now rotated.

Of course, if you think about it, you really only need to translate & reverse translate the first point (x1,y1), and not both of them since translating the rotational axis point will always give you (0,0). This whole thing can be simplified down to

x1'' = ( (x1-x2)*cos(theta) - (y1-y2)*sin(theta) ) + x2

y1'' = ( (x1-x2)*sin(theta) + (y1-y2)*cos(theta) ) + y2

x1 = x1''

y1 = y1''

Of course should ideally optimize this so that you do less calculations (especially the sin and cos).