You basically have this:
[ONES_COLUMN, X_COLUMN, Y_COLUMN] * p = DATA
You know all the CAPS stuff. So just use the standard least squares solution to find p. I.e., if you had the generic problem A*x = b, how would you find the least squares solution for x?