To solve this optimization problem, we will use linear programming. The goal is to maximize profit given certain constraints.

Let's denote:
- \(x_1\) as the number of mountain bikes to stock,
- \(x_2\) as the number of road bikes to stock.

The objective function (to maximize profit) can be represented as:
\[300x_1 + 500x_2\]

Constraints are:
1. The total number of bikes should not exceed 150: 
\[x_1 + x_2 \leq 150\]
2. The total cost of bikes in stock should not exceed $40,000:
\[750x_1 + 1000x_2 \leq 40000\]
3. Non-negativity constraints (since you cannot stock a negative number of bikes):
\[x_1 \geq 0, x_2 \geq 0\]

Given this formulation, we can now translate it into Gurobi code in Python.

```python
from gurobipy import *

# Create a model
m = Model("Bike_Stocking")

# Define variables
x1 = m.addVar(lb=0, vtype=GRB.INTEGER, name="Mountain_Bikes")
x2 = m.addVar(lb=0, vtype=GRB.INTEGER, name="Road_Bikes")

# Set the objective function
m.setObjective(300*x1 + 500*x2, GRB.MAXIMIZE)

# Add constraints
m.addConstr(x1 + x2 <= 150, "Total_Bikes")
m.addConstr(750*x1 + 1000*x2 <= 40000, "Total_Cost")

# Optimize the model
m.optimize()

# Print the results
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Mountain Bikes: {x1.x}")
    print(f"Road Bikes: {x2.x}")
    print(f"Maximum Profit: {m.objVal}")
else:
    print("No optimal solution found")
```