To solve the optimization problem described, we need to formulate it as a linear programming problem. The goal is to maximize profit given the constraints on cotton availability and total number of animals that can be made.

Let's denote:
- \(x\) as the number of mini bears produced,
- \(y\) as the number of mini dogs produced.

The objective function, which represents the total profit, is given by \(40x + 47y\), since each mini bear sold generates $40 in profit and each mini dog sold generates $47 in profit.

The constraints are:
1. Cotton availability: \(8x + 7y \leq 400\), because each mini bear requires 8 units of cotton and each mini dog requires 7 units, with a total of 400 units available.
2. Total number of animals: \(x + y \leq 40\), since the artist can make at most 40 animals due to time constraints.
3. Non-negativity constraints: \(x \geq 0\) and \(y \geq 0\), because the number of mini bears and dogs produced cannot be negative.

To solve this problem using Gurobi in Python, we first need to ensure that the Gurobi package is installed in our environment. If not, it can be installed via pip:

```bash
pip install gurobipy
```

Now, let's formulate the Gurobi code for this optimization problem:

```python
from gurobipy import *

# Create a new model
m = Model("artist_profit")

# Define variables
x = m.addVar(lb=0, name="mini_bears")
y = m.addVar(lb=0, name="mini_dogs")

# Objective function: Maximize profit
m.setObjective(40*x + 47*y, GRB.MAXIMIZE)

# Constraints
m.addConstr(8*x + 7*y <= 400, "cotton_availability")
m.addConstr(x + y <= 40, "total_animals")

# Optimize model
m.optimize()

# Print results
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Mini bears: {x.x}")
    print(f"Mini dogs: {y.x}")
    print(f"Total profit: ${40*x.x + 47*y.x:.2f}")
else:
    print("No optimal solution found")
```

This code sets up the optimization problem as described, solves it using Gurobi's linear programming solver, and then prints out the optimal number of mini bears and dogs to produce along with the total profit. If no optimal solution is found (which could happen if the problem is infeasible), it will indicate that instead.